Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Utilisation de capteurs et composants électroniques avec Arduino.
Une fiche de tutoriel pour chaque.

Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar tiptop » Lun 27 Oct 2014 21:02

Tutoriel d'utilisation de l'écran graphique OLED de 128x64 pixels I2C avec Arduino.

Image.Image

Composants utilisés

Image
Principe de fonctionnement
Compatible avec Arduino, cet écran graphique plat est facile à intégrer à tous vos montages.
Il comporte un affichage de 128 x 64 pixels à très forte luminosité et contraste ajustable.
La technologie OLED est très lumineuse sans avoir besoin de rétro éclairage et reste lisible même sous inclinaison.

Le module peut être commandé par 5 interfaces, dont une interface série SPI ou une interface I2C, avec un contrôleur SSD1306.
l'interface est sélectionnée par 3 jumpers à souder :
Image


Caractéristiques
  • Modèle SSD1306 JY-MCU Oled module, v1.5
  • Ecran graphique de 128 x 64 pixels
  • Technologie OLED (organic leds)
  • Bicolore jaune / bleu (haut et bas de l'écran)
  • Taille 0.96 "
  • Taille 26.70 x 19.26 x 11.2 mm
  • Zone active 21.74 mm x 11.2 mm

Câblage du module
Le circuit comporte un brochage à 16 pins (de haut en bas, et de gauche à droite, vu de dos).

Image


Les fonctions des broches :
Image

Interface
Le driver I2C est un SSD1306. Il offre au choix 5 modes d'interface : 8-bit 68xx / 80xx parallèle, 3 ou 4 fils SPI, I2C.
Le choix du type d'interface se fait avec les 3 résistances jumpers à souder au verso (b0, b1, b2).

Image

Utilisation en I2C
Pour l'utiliser en mode I2C, (4 broches), configurer les résistances au dos du module sur
b0 = 0, b1 = 1, b2 = 0.

L'adresse I2C du module est modifiable (2 possibilités : b011 1100” ou b011 1101)
  • 0x3C - pin DC branchée sur GND
  • 0x3D - pin DC branchée sur 3.3V.

Branchement en I2C
Module (i2C) --> Arduino
  • 3.3 --> 3.3V alimentation
  • Gnd masse --> Gnd arduino
  • CS Chip select --> sur low
  • RS Reset Signal input --> pin 4
  • DC--> sélection d'adresse en mode I2C (Slave Adress SA0, sur la masse par ex.)
  • D0 (Serial clock input SCL) --> Pin A5
  • D1 (SDA-input ) relié avec D2 (SDA-output) --> Pin A4

Il faut utiliser des résistances de pullup externes sur SDA et SCL.
Attention, il n'y a pas encore de librairie I2C disponible, donc il est préférable d'utiliser le module en interface série SPI.

Autre utilisation en mode SPI SERIAL
Le SPI (Serial Peripheral Interface) est un bus de données série synchrone bidirectionnel.
Il présente l'intérêt d'utiliser assez peu de pins de câblage, il est un peu plus rapide que l'I2C.

Par défaut le module est en mode d'interface 8080 (résistances sur bo=0, b1=1, b2=1).
Choisir entre 4SPI ou 3SPI et configurer les résistances au dos du module.

Dans cet exemple, nous utilisons le mode d'interface 4SPI.
Il faut donc brancher les 3 résistances de configuration sur
b0 = 0, b1 = 0, b2 = 0.

Câblage module (mode 4-SPI) --> Arduino
  • 3.3V Vcc -->3.3 V (il n'y a pas besoin de décaler les niveaux, module "5V ready").
  • GND masse --> GND.
  • D0 Serial Clock Input (SCLK ) -->pin 10.
  • D1 (MOSI data) --> pin 9.
  • RST (Reset) --> pin 13.
  • DC (Data / Command) --> pin 11 (en mode 3-wire on met sur low)
  • CS (Chip Select) --> port pin 12 (doit être unique pour chaque dispositif SPI).

Dans le code on mettra :
Code: Tout sélectionner
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13


Image.Image

Librairie Arduino SSD1306
Charger la librairie SSD136 pour piloter le contrôleur de l'écran, disponible ici
https://github.com/adafruit/Adafruit_SSD1306

La librairie est capable de gérer plusieurs tailles d'écrans OLED.
Déziper le fichier ZIP puis le placer dans son répertoire Arduino /libraries, et redémarrer l'IDE Arduino pour prendre en compte cette installation.

Sélectionner l'écran de type SSD1306_128_64, 128x64 pixel display (ligne 27 de la librairie SSD136.h). Il est en principe déjà choisi par défaut.

Programmation de l'écran

On indique au programme la taille de son écran au début du fichier : Adafruit_SSD1306.h

Image.Image


Code: Tout sélectionner
//**********************************************************
//  Ecran OLED 128 x 64 pixels graphiques
// commande en mode 4SPI
// Brancher les 3 jumpers d'interface sur b0=0 b1=0 b2=0
// Plus de détails de fonctionnement sur tiptopboards.free.fr 
// 28 10 2014
// D'après electrodragon.com  (en anglais)
//**********************************************************

#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
 
#include <SSD1306.h>
 
SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
 
 
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };
 
 
void setup()   {               
  Serial.begin(9600);
 
  // If you want to provide external 7-9V VCC, uncomment next line and comment the one after
  //oled.ssd1306_init(SSD1306_EXTERNALVCC);
 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
 
  // init done
 
  oled.display(); // show splashscreen
  delay(2000);
  oled.clear();   // clears the screen and buffer
 
  // Fill screen
  oled.fillrect(0, 0, SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, WHITE);
  oled.display();
  delay(2000);
 
  // draw a single pixel
  oled.setpixel(10, 10, WHITE);
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw many lines
  testdrawline();
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw rectangles
  testdrawrect();
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw multiple rectangles
  testfillrect();
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw mulitple circles
  testdrawcircle();
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw a white circle, 10 pixel radius, at location (32,32)
  oled.fillcircle(32, 32, 10, WHITE);
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw the first ~12 characters in the font
  testdrawchar();
  oled.display();
  delay(2000);
  oled.clear();
 
  // draw a string at location (0,0)
  oled.drawstring(0, 0, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation");
  oled.display();
  delay(2000);
  oled.clear();
 
  // miniature bitmap display
  oled.drawbitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  oled.display();
 
  // invert the display
  oled.ssd1306_command(SSD1306_INVERTDISPLAY);
  delay(1000);
  oled.ssd1306_command(SSD1306_NORMALDISPLAY);
  delay(1000);
 
  // draw a bitmap icon and 'animate' movement
  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}
 
 
void loop()                     
{
  for (uint8_t i=0; i<SSD1306_LCDWIDTH; i++) {
    for (uint8_t j=0; j<SSD1306_LCDHEIGHT; j++) {
      oled.setpixel(i, j, WHITE);
      oled.display();
    }
  }
 
 
}
 
 
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];
  srandom(666);     // whatever seed
 
  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = random() % 5 + 1;
 
    Serial.print("x: ");
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(" y: ");
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(" dy: ");
    Serial.println(icons[f][DELTAY], DEC);
  }
 
  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      oled.drawbitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
    }
    oled.display();
    delay(200);
 
    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      oled.drawbitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > SSD1306_LCDHEIGHT) {
        icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
        icons[f][YPOS] = 0;
        icons[f][DELTAY] = random() % 5 + 1;
      }
    }
  }
}
 
 
void testdrawchar(void) {
  for (uint8_t i=0; i < 168; i++) {
    oled.drawchar((i % 21) * 6, i/21, i);
  }   
}
 
void testdrawcircle(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
    oled.drawcircle(63, 31, i, WHITE);
  }
}
 
void testdrawrect(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
    oled.drawrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, WHITE);
  }
}
 
void testfillrect(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i++) {
      // alternate colors for moire effect
    oled.fillrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, i%2);
  }
}
 
void testdrawline() {
  for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
    oled.drawline(0, 0, i, SSD1306_LCDHEIGHT-1, WHITE);
    oled.display();
  }
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
    oled.drawline(0, 0, SSD1306_LCDWIDTH-1, i, WHITE);
    oled.display();
  }
 
  delay(1000);
 
  for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
    oled.drawline(i, SSD1306_LCDHEIGHT-1, 0, 0, BLACK);
    oled.display();
  }
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
    oled.drawline(SSD1306_LCDWIDTH - 1, i, 0, 0, BLACK);
    oled.display();
  }
}



Démonstration des possibilités d'affichages de texte, rectangles, lignes, disques,cercles, dessins graphiques bitmaps, animations
Image.Image.Image.Image.Image.Image

Les fonctions graphiques utiles

oled.fillcircle(32, 32, 10, WHITE); dessine un disque plein
oled.drawcircle(63, 31, i, WHITE); dessine un cercle
oled.fillrect dessine un rectangle plein
oled.drawline dessine une ligne
oled.drawbitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); dessine un bitmap de taille définie à l'emplacement voulu

Image.Image
Ex: Réalisation d'un afficheur "7 segments" avec des rectangles tracés sur l'écran graphique.

Les fonctions texte

oled.drawstring(0, 0, "Mon texte ici ..."); écrit un texte à l'emplacement indiqué.
On dispose de 8 lignes de 21 caractères avec la fonte ASCII-standard 5x7 (définie dans le fichier librairie/SSD136/glcdfont.c)
  • Les 2 lignes du haut sont jaunes (0 et 1)
  • Les 6 lignes de dessous (2 à 7) sont bleues.
Code: Tout sélectionner
   oled.drawstring(0,1,"BONJOUR");  //colonne 0, ligne 1 jaune
 oled.drawstring(0,2,"bienvenue");  //colonne 0, ligne 2 bleue

oled.drawchar écrire un caractère
Code: Tout sélectionner
oled.drawchar(5,5,65);  //caractre asccii 65 pour A
 


Image.Image



Dessin de bitmap graphique

L'utilitaire LCD-Assistant permet de préparer les bitmaps à afficher.
Dessiner une image bitmap monochrome (avec Photoshop, Paint...) et l'enregistrement BMP.
Image

exemple de dessin (vite fait) sous Photoshop :
Image

Ouvrir ce fichier dans LCD-Assistant, le sauvegarder en fichier texte avec les options :
size width=128, height=64, Size endianness = little, 8pixels/byte
Image

Ce texte sera à coller ensuite dans son code pour utiliser le bitmap.
Image
Code: Tout sélectionner
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------

const unsigned char test [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0xE0,
0xF0, 0xF0, 0x78, 0x78, 0x78, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x78, 0x78, 0x78, 0xF0, 0xF0,
0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x03, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF8, 0x7C, 0x1E, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01,
0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1E, 0x7C, 0xF8, 0xF0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1F, 0x3F, 0x7F,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7C, 0xF0, 0xE0, 0xC0, 0x80, 0x80, 0x00, 0x03,
0x07, 0x0F, 0x1F, 0x3F, 0x3E, 0x7E, 0x7C, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0x7E, 0x7F, 0x1F, 0x00,
0x00, 0x00, 0x80, 0x80, 0xC0, 0xE0, 0xF0, 0x7C, 0x3F, 0x1F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0,
0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFE, 0xFE, 0xFC, 0xFC, 0x3C, 0x78, 0x78, 0x78, 0x78, 0x78, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x78, 0x78, 0x78, 0x78, 0xF8, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE,
0xFF, 0xFF, 0xE7, 0xC7, 0xC3, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xC0, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x3F, 0x1F, 0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x3F,
0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0,
0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F,
0x1F, 0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};


Le code pour afficher le dessin
Code: Tout sélectionner
//*****************************************************
// affichage de mon dessin graphique bitmap sur
//  Ecran OLED 128 x 64 pixels
// tiptopboards.com 28 10 2014
//*****************************************************
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
 
#include <SSD1306.h>
 
SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
 
 
 // Mon dessin de 128 x 64 occupe tout l'écran
#define LOGO_GLCD_HEIGHT 64
#define LOGO_GLCD_WIDTH  128
// Le dessin sous forme d'octets
static unsigned char __attribute__ ((progmem)) logo_glcd_bmp[]= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xF0, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0xE0,
0xF0, 0xF0, 0x78, 0x78, 0x78, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x78, 0x78, 0x78, 0xF0, 0xF0,
0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x03, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF8, 0x7C, 0x1E, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01,
0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1E, 0x7C, 0xF8, 0xF0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1F, 0x3F, 0x7F,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7C, 0xF0, 0xE0, 0xC0, 0x80, 0x80, 0x00, 0x03,
0x07, 0x0F, 0x1F, 0x3F, 0x3E, 0x7E, 0x7C, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0x7E, 0x7F, 0x1F, 0x00,
0x00, 0x00, 0x80, 0x80, 0xC0, 0xE0, 0xF0, 0x7C, 0x3F, 0x1F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0,
0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFE, 0xFE, 0xFC, 0xFC, 0x3C, 0x78, 0x78, 0x78, 0x78, 0x78, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x78, 0x78, 0x78, 0x78, 0xF8, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE,
0xFF, 0xFF, 0xE7, 0xC7, 0xC3, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xC0, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x3F, 0x1F, 0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x3F,
0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0xF0,
0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F,
0x1F, 0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

 // fin du fichier graphique
 
void setup()   {               
  Serial.begin(9600);
  oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
   oled.clear();   // clears the screen and buffer
 
 
 // Affichage de textes
  oled.drawstring(0,1,"BONJOUR");  //colone 0 ligne 1 jaune
  oled.drawstring(5,4,"TipTopBoards.com");  //bleu
  oled.display();
  delay(9000);
  oled.clear();
 
 // Affichage de mon dessin en position 0,0
 //128 colones x 64 lignes de pixels
   oled.drawbitmap(0, 0,  logo_glcd_bmp, 128, 64, 1);
   oled.display();

 

void loop()                     
{
 
 // inversion video
  oled.ssd1306_command(SSD1306_INVERTDISPLAY);
  delay(2000);
  oled.ssd1306_command(SSD1306_NORMALDISPLAY);
  delay(2000);
}



La technologie OLED
Image

Image.Image

Références
Adafruit (en anglais), branchement en mode SPI (non testé).
https://learn.adafruit.com/monochrome-o ... d-examples
avec exemple de création de bitmaps.

Avec la librairie SeedOLED (non testé ni utilisée ici).
http://www.seeedstudio.com/wiki/Grove_- ... ay_0.96%22

Tutoriel en anglais avec un branchement sur 6 pins (D0, D1, Rst, Dc, Vcc Gnd) en mode SPI
http://www.instructables.com/id/How-to- ... no-module/
pour ce module SPI/I2C
http://smart-prototyping.com/Prototypin ... -blue.html


OLED SPI Interface with Arduino Tutorial (by Chao) , Un bon tutoriel complet en interface 4-SPI (en anglais) avec un code de démo Arduino
http://www.electrodragon.com/oled-spi-wiring-tutorial/
http://www.electrodragon.com/product/mini-oled-1/

La datasheet détaillée du module OLED (avec le brochage, les modes de commande SPi / I2C, les write_command..) 30 pages.
http://s3.electrodragon.com/wp-content/ ... 128064.pdf

Applications
Une montre avec connexion bluetooth Android
http://atmelcorporation.wordpress.com/2 ... %E2%80%A8/
tiptopboards - admin
Avatar de l’utilisateur
tiptop
Administrateur du site
 
Messages: 93
Inscription: Mar 13 Aoû 2013 20:38
Localisation: 38

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar JS7777 » Ven 2 Jan 2015 02:54

Les deux dernières images sur votre tuto, le bonhomme : comment vous changez le style de l'écran oled ? (noir sur bleu bleu sur noir)

Votre tuto marche t-il si sur l'écran oled il y a que 4 pin (GND, VCC, SCL, SCA) ?
JS7777
 
Messages: 4
Inscription: Mer 31 Déc 2014 18:01

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar tiptop » Ven 16 Jan 2015 14:06

C'est fait avec une simple inversion vidéo
Code: Tout sélectionner
// inversion video
  oled.ssd1306_command(SSD1306_INVERTDISPLAY);
  delay(2000);
  oled.ssd1306_command(SSD1306_NORMALDISPLAY);
  delay(2000);


Le protocole I2C n'a besoin que de ces 4 pins. Les autres broches du module servent à d'autres types de commande (SPI, ou montage parallèle...).
tiptopboards - admin
Avatar de l’utilisateur
tiptop
Administrateur du site
 
Messages: 93
Inscription: Mar 13 Aoû 2013 20:38
Localisation: 38

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar grostoto » Mar 19 Mai 2015 12:08

bonjour

j'ai le module avec 4 pins:

je le cable comme ceci:

VCC: 3.3v
gnd: gnd
SCL: A5
SDA: A4

est ce que cela est bon ? (car rien ne s'allume).

merci
grostoto
 
Messages: 5
Inscription: Lun 18 Mai 2015 22:31

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar grostoto » Ven 22 Mai 2015 23:33

salut

j'ai réussi à le faire fonctionner en utilisant la librairie ici
http://forum.arduino.cc/index.php?actio ... tach=72327

http://forum.arduino.cc/index.php?topic=219419.75

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);
grostoto
 
Messages: 5
Inscription: Lun 18 Mai 2015 22:31

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar corrado s2 » Dim 20 Sep 2015 21:11

Bonsoir, je suis en train de réaliser un "car gauge" c'est à dire que je désire afficher quelque infos tel que température et pression d'huile, température échappement ( egt ), via quelques capteur sur mon écran OBD de mon porte instrument d'une du TT.
Pour l'instant tout fonctionner très bien sur un écran OLED, via les signaux Data, CLK, RST, ,3,3V, GND, DC.
Mais pour attaquer l'écran centrale du porte instrument on ne peut utiliser que les signaux DATA, clock, et enable.
Please help me.
corrado s2
 
Messages: 2
Inscription: Ven 18 Sep 2015 16:51

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar corrado s2 » Jeu 1 Oct 2015 05:03

Il n'y a pas beaucoup d'aide sur ce forum visiblement
corrado s2
 
Messages: 2
Inscription: Ven 18 Sep 2015 16:51

Re: Tutoriel écran OLED 128x64 pixels I2C avec Arduino

Messagepar pierlau38 » Dim 25 Oct 2015 07:59

bjr,

J'ai également le module en 4 fils, que j'utilise donc avec le protocole I2C.

Voici le cablage (idem grostoto ci-dessus) :

OLED / UNO
VCC au +3.3
GND à la masse
SDA Analog IN 4
SCL Analog IN 5

On peut utiliser la lib U8glib comme grostoto. De mon côté, j'ai pris la lib adafruit_SSD1306 Master

Code: Tout sélectionner
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


Mais ca ne marche du premier coup :-( !

On trouve sur des forums qu'il faut changer l'adresse indiquée à la ligne 61 de l'exemple (celui fournit avec la librairie) l'adresse I2C du module.
Pour cela, remplacer :
Code: Tout sélectionner
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)

par :
Code: Tout sélectionner
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 


Et avec ca, tout s'affiche !
Voila en espérant que cela vous aide ;-)
pierlau38
 
Messages: 1
Inscription: Sam 24 Oct 2015 21:40


Retourner vers Capteurs et composants

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 5 invités