![]() |
![]() |
![]() |
Dans ce tutoriel, nous allons apprendre comment câbler et afficher du texte, des images et faire de petites animations sur un mini écran OLED monochrome SSD1306 0.96” avec un Arduino. Cet écran piloté par un micro-contrôleur SSD1306 utilise le bus I2C pourra communiquer avec un Arduino, un ESP8266 et même un mini-PC (Raspberry Pi, Orange Pi…). Cet écran de 0,96” est capable d’afficher 128×64 pixels.Vous pouvez trouver cet écran OLED chez Adafruit ou Sparkfun par exemple. On le trouve également pour moins de 3€ chez de nombreux fabricants asiatiques. Ces écrans sont de bonne qualité. Adafruit et Sparkfun ont développés des librairies qui permettent d’afficher très facilement du texte, des images et mêmes de faire des animations à base de formes géométriques très simplement.
Sommaire
- 1 Câblage de l’écran OLED I2C SSD1306 128x64p 0.96″ sur Arduino
- 2 Matériel nécessaire
- 3 Comment trouver l’adresse de l’écran SSD1306 sur le bus I2C ?
- 4 Rappel : comment installer une librairie sur l’IDE Arduino ?
- 5 Test des librairies Adafruit et Sparkfun pour piloter un écran OLED SSD1306
- 6 Comment préparer et afficher des images Bitmaps
Câblage de l’écran OLED I2C SSD1306 128x64p 0.96″ sur Arduino
L’utilisation de l’interface I2C permet de réduire très fortement le câblage de cet écran OLED. Cet écran n’étant pas disponible dans la librairie d’Adafruit, je l’ai remplacé par son cousin plus petit, 128 x 32 pixels. L’écran est alimenté en 3.3V, il utilise le même micro-contrôleur SSD1306.
Si vous disposez d’un Arduino Uno, relié le Pin A4 sur le Pin SDA (Serial DAta) de l’écran et le port A5 sur le Pin SCL (Serial CLock). Certaines cartes disposent directement des Pins dédiés SDA/SCL. Sinon, voici un petit tableau qui récapitule les connecteurs SDA et SCL pour différentes cartes Arduino courantes (d’après cet article).
Carte | SDA | SCL | |
![]() |
Arduino Uno | A4 | A5 |
![]() |
Arduino Mega | 20
Marqué SDA |
21
Marqué SCL |
![]() |
Arduino Leonardo | D2 | D3 |
Matériel nécessaire
Pour réaliser le montage de ce projet vous aurez besoin du matériel suivant (liens commerciaux) :
Pour ce tutoriel, nous allons utiliser un écran de 0,96” permettant d’afficher 128×64 pixels mais il existe d’autres résolutions et d’autres tailles disponibles. En voici quelques unes.
N’oubliez pas de vérifier que la résolution est supportée par la librairie. Par exemple, la librairie Adafruit supporte les écrans de 128×64 ou 128×32 pixels.
Enfin, il existe principalement trois couleurs d’affichage.
Comment trouver l’adresse de l’écran SSD1306 sur le bus I2C ?
Avant de pouvoir utiliser l’écran OLED SSD1306, il va falloir configurer le port sur lequel celui-ci ce trouve sur le bus I2C. Pour cela, Nick Gammon’s a développé un petit programme Arduino pour trouver le port I2C sur lequel est branché l’écran OLED. Le programme scrute en boucle et recherche les appareils I2C connectés au port série toutes les 5 secondes mais on peut ajuster le délai de rafraichissement en ajustant le délai en fin de boucle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
/* Scanner I2C d'après le projet initial de Nick Grammon's http://playground.arduino.cc/Main/I2cScanner Projets DIY - Mars 2016 - https://www.projetsdiy.fr */ // -------------------------------------- // i2c_scanner // // Version 1 // This program (or code that looks like it) // can be found in many places. // For example on the Arduino.cc forum. // The original author is not know. // Version 2, Juni 2012, Using Arduino 1.0.1 // Adapted to be as simple as possible by Arduino.cc user Krodal // Version 3, Feb 26 2013 // V3 by louarnold // Version 4, March 3, 2013, Using Arduino 1.0.3 // by Arduino.cc user Krodal. // Changes by louarnold removed. // Scanning addresses changed from 0...127 to 1...119, // according to the i2c scanner by Nick Gammon // http://www.gammon.com.au/forum/?id=10896 // Version 5, March 28, 2013 // As version 4, but address scans now to 127. // A sensor seems to use address 120. // Version 6, November 27, 2015. // Added waiting for the Leonardo serial communication. // // // This sketch tests the standard 7-bit addresses // Devices with higher bit address might not be seen properly. // #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("Appareil I2C trouve a cette adresse 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Erreur inconnue a cette address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("Aucun appareil I2C trouve\n"); else Serial.println("Fin\n"); delay(5000); // wait 5 seconds for next scan } |
Rappel : comment installer une librairie sur l’IDE Arduino ?
Pour ceux qui découvrent l’IDE Arduino, vous aurez besoin d’ajouter des librairies pour faire fonctionner l’écran OLED. Certaines librairies sont directement disponibles depuis le gestionnaire de librairies. C’est le cas par exemple de la librairie Adafruit pour le SSD1306. Dans le menu croquis, aller dans Inclure une bibliothèque puis Gérer les bibliothèques.
D’autres bibliothèques sont disponibles sur GitHub. C’est par exemple le cas de la bibliothèque (library en anglais) de Sparkfun. Dans ce cas, commencez par télécharger la librairie mais ne compressez pas le Zip. Ensuite, allez dans Croquis -> Inclure une librairie -> Ajouter la bibliothèque .ZIP et choisissez le zip de la librairie à importer.
Vous pouvez maintenant aller dans Fichier -> Exemples pour découvrir les exemples proposés dans la librairie.
Pour utiliser une librairie dans vos projets, déclarez la en début de projet, par exemple
1 |
#include <Adafruit_GFX.h> |
Test des librairies Adafruit et Sparkfun pour piloter un écran OLED SSD1306
Pour gérer l’affichage sur votre écran OLED, il y a plusieurs librairies Open Source à notre disposition. Pour cet article, je vais vous présenter les deux principales. La librairie développée par Adafruit et celle de Sparkfun.
Librairies Adafruit_GFX et Adafruit_SSD1306
Adafruit a développé une librairie très puissante qui va nous permettre de gérer l’affichage de notre mini écran mais aussi de tracer plein de chose très facilement grâce à la librairie dédiée, GFX Library. Vous pouvez récupérer la librairie Adafruit SSD1306 sur le github https://github.com/adafruit/Adafruit_SSD1306 et la librairie GFX ici https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip.
Liste des fonctions de la librairie disponibles
Fonctions de la librairie Adafruit_SSD1306 | |
Adafruit_SSD1306 display(OLED_RESET) | initialise l’objet display(Pin pour le reset) |
display() | Actualise l’affichage |
clearDisplay() | Efface l’écran et le buffer |
invertDisplay(bool) | inverse l’affichage (true ou false) |
Fonctions Adafruit_GFX | |
drawPixel(uint16_t x, uint16_t y, uint16_t color) | Dessine un pixel en X,Y de la couleur color |
drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) | Dessine une ligne de X1,Y1 à x2,Y2 de la couleur color |
drawFastVLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color)
drawFastHLine(uin86_t x0, uin86_t y0, uint8_t length, uint16_t color); |
Tracé optimisé de lignes horizontales et verticales |
drawRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color)
fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color) |
Dessine un rectangle depuis X,Y de largeur w et hauteur h
idem mais plein |
drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color)
fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) |
Dessine un cercle de centre X,Y et de rayon r
idem mais le cercle est plein |
drawRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color)
fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color) |
Idem rectangle mais avec un arrondi de rayon raduis aux angles |
drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) |
Dessine un triangle en spécifiant les coordonnées de chaque sommets (x0,y1), (x2,y2), (x3,y3) |
drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint16_t bg, uint8_t size) | Dessine un caractère en x,y |
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) | Affiche un bitmap en x,y de largeur w et hauteur t |
fillScreen(uint16_t color); | Colorie entièrement l’écran dans la couleur spécifiée |
setRotation(uint8_t rotation) | Rotation de l’affichage : 0 -> 0°, 1 -> 90°, 2 -> 180°, 3 -> 270° |
Le paramètre color permettant de définir la couleur d’affichage uniquement sur les écrans couleur est disponible dans toutes les fonctions graphiques de la librairie GFX. Pour plus d’informations, vous pouvez consulter ce document de formation en anglais.
La librairie Adafruit_GFX est utilisée par d’autres librairies dédiées à chaque (microcontroleur) écran.
Afficher du texte
L’affichage d’un texte demande un peu plus de travail. Il est nécessaire de modifier les paramètres d’affichage paramètre par paramètre. Voici un petit exemple pour afficher Hello Word en 0,0:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
display.setTextSize(1); // setTextSize applique est facteur d'échelle qui permet d'agrandir ou réduire la font display.setTextColor(WHITE); // La couleur du texte display.setCursor(0,0); // On va écrire en x=0, y=0 display.println("Hello, world!"); // un println comme pour écrire sur le port série display.setTextColor(BLACK, WHITE); // On inverse les couleurs, le fond devient noir display.println("Hello, world!"); // Vous pouvez changer à la volée de Font (pour cela vous devez la déclarer comme une librairie en début de projet, par exemple #include <Fonts/FreeMono9pt7b.h>) display.setFont(&FreeMono9pt7b); display.setTextColor(WHITE); display.println("Hello, world!"); display.setFont(); // Pour revenir à la Font par défaut |
Par contre, vous pouvez oublier les accents, ils ne sont pas gérés dans les Fonts disponibles.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
/* Programme de démo pour écran OLED 128x64 pixels I2C basé sur le contrôleur SSD1306 Ajout de traduction en français Projets DIY - mars 2016 - https://www.projetsdiy.fr */ /********************************************************************* 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 This example is for a 128x64 size display using I2C to communicate 3 pins are required to interface (2 I2C and one reset) Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information All text above, and the splash screen must be included in any redistribution *********************************************************************/ #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); #define NUMFLAKES 10 #define XPOS 0 #define YPOS 1 #define DELTAY 2 #define LOGO16_GLCD_HEIGHT 16 #define LOGO16_GLCD_WIDTH 16 // Logo Adafruit static const unsigned char PROGMEM logo16_glcd_bmp[] = { B00000000, B11000000, B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011, B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111, B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111, B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000, B00000000, B00110000 }; #if (SSD1306_LCDHEIGHT != 64) #error("Height incorrect, please fix Adafruit_SSD1306.h!"); #endif void setup() { Serial.begin(9600); // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) //Utiliser le scanner I2C pour trouver le port série sur lequel se trouve votre écran display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) // init done display.display(); // show splashscreen // Affiche le logo Adafruit par défaut delay(2000); display.clearDisplay(); // clears the screen and buffer // Efface l'écran // draw a single pixel // Dessine un pixel blanc aux coordonnées 10,10 display.drawPixel(10, 10, WHITE); display.display(); delay(2000); display.clearDisplay(); // draw many lines // Dessine plusieurs lignes testdrawline(); display.display(); delay(2000); display.clearDisplay(); // draw rectangles // Des rectangles testdrawrect(); display.display(); delay(2000); display.clearDisplay(); // draw multiple rectangles // Plusieurs rectangles imbriqués testfillrect(); display.display(); delay(2000); display.clearDisplay(); // draw mulitple circles // Des cercles testdrawcircle(); display.display(); delay(2000); display.clearDisplay(); // draw a white circle, 10 pixel radius // Un cercle blanc de 10 pixels de rayon display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); display.display(); delay(2000); display.clearDisplay(); testdrawroundrect(); // Rectangle arondi delay(2000); display.clearDisplay(); testfillroundrect(); // idem mais rempli delay(2000); display.clearDisplay(); testdrawtriangle(); // triangle delay(2000); display.clearDisplay(); testfilltriangle(); // triangle plein delay(2000); display.clearDisplay(); // draw the first ~12 characters in the font / 12 caractères testdrawchar(); display.display(); delay(2000); display.clearDisplay(); // draw scrolling text // scrolling d'un texte testscrolltext(); delay(2000); display.clearDisplay(); // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Hello, world!"); display.setTextColor(BLACK, WHITE); // 'inverted' text display.println(3.141592); display.setTextSize(2); display.setTextColor(WHITE); display.print("0x"); display.println(0xDEADBEEF, HEX); display.display(); delay(2000); // miniature bitmap display display.clearDisplay(); display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); display.display(); // invert the display display.invertDisplay(true); delay(1000); display.invertDisplay(false); delay(1000); // draw a bitmap icon and 'animate' movement testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); } void loop() { } void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { uint8_t icons[NUMFLAKES][3]; // initialize for (uint8_t f=0; f< NUMFLAKES; f++) { icons[f][XPOS] = random(display.width()); 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++) { display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); } display.display(); delay(200); // then erase it + move it for (uint8_t f=0; f< NUMFLAKES; f++) { display.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] > display.height()) { icons[f][XPOS] = random(display.width()); icons[f][YPOS] = 0; icons[f][DELTAY] = random(5) + 1; } } } } void testdrawchar(void) { display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); for (uint8_t i=0; i < 168; i++) { if (i == '\n') continue; display.write(i); if ((i > 0) && (i % 21 == 0)) display.println(); } display.display(); } void testdrawcircle(void) { for (int16_t i=0; i<display.height(); i+=2) { display.drawCircle(display.width()/2, display.height()/2, i, WHITE); display.display(); } } void testfillrect(void) { uint8_t color = 1; for (int16_t i=0; i<display.height()/2; i+=3) { // alternate colors display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2); display.display(); color++; } } void testdrawtriangle(void) { for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) { display.drawTriangle(display.width()/2, display.height()/2-i, display.width()/2-i, display.height()/2+i, display.width()/2+i, display.height()/2+i, WHITE); display.display(); } } void testfilltriangle(void) { uint8_t color = WHITE; for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) { display.fillTriangle(display.width()/2, display.height()/2-i, display.width()/2-i, display.height()/2+i, display.width()/2+i, display.height()/2+i, WHITE); if (color == WHITE) color = BLACK; else color = WHITE; display.display(); } } void testdrawroundrect(void) { for (int16_t i=0; i<display.height()/2-2; i+=2) { display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE); display.display(); } } void testfillroundrect(void) { uint8_t color = WHITE; for (int16_t i=0; i<display.height()/2-2; i+=2) { display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color); if (color == WHITE) color = BLACK; else color = WHITE; display.display(); } } void testdrawrect(void) { for (int16_t i=0; i<display.height()/2; i+=2) { display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE); display.display(); } } void testdrawline() { for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(0, 0, i, display.height()-1, WHITE); display.display(); } for (int16_t i=0; i<display.height(); i+=4) { display.drawLine(0, 0, display.width()-1, i, WHITE); display.display(); } delay(250); display.clearDisplay(); for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(0, display.height()-1, i, 0, WHITE); display.display(); } for (int16_t i=display.height()-1; i>=0; i-=4) { display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); display.display(); } delay(250); display.clearDisplay(); for (int16_t i=display.width()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); display.display(); } for (int16_t i=display.height()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); display.display(); } delay(250); display.clearDisplay(); for (int16_t i=0; i<display.height(); i+=4) { display.drawLine(display.width()-1, 0, 0, i, WHITE); display.display(); } for (int16_t i=0; i<display.width(); i+=4) { display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE); display.display(); } delay(250); } void testscrolltext(void) { display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(10,0); display.clearDisplay(); display.println("scroll"); display.display(); display.startscrollright(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrollleft(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrolldiagright(0x00, 0x07); delay(2000); display.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); } |
Librairie Micro_OLED de Sparkfun (compatible SSD1306)
La seconde librairie à notre disposition est celle développée par Sparkfun. Elle est disponible sur le github de Sparkfun. Elle est plus compacte que celle d’Adafruit mais en contrepartie elle offre (un peu) moins de fonctions de tracé. Cette librairie peut fonctionner aussi bien sur I2C qu’en SPI avec votre SSD1306. Vous pouvez tester l’un ou l’autre directement en ajustant vos paramètres dans le code d’essai ci-dessous. La librairie Sparkfun est livrée avec 4 exemples :
- Hello
- Clock : affiche une montre qui actualise la petite aiguille à chaque seconde
- Cube : dessine un cube 3D en rotation
- Demo : une démo qui passe en revue toutes les possibilités de la librairie
- DrawBitmap : Affiche un bitmap
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
/* Demo pour controler un écran mini OLED 128x64 pixels Configuré en I2C Projets DIY - Mars 2016 - https://www.projetsdiy.fr */ /****************************************************************************** * MicroOLED_Demo.ino * SFE_MicroOLED Library Demo * Jim Lindblom @ SparkFun Electronics * Original Creation Date: October 27, 2014 * * This sketch uses the MicroOLED library to draw a 3-D projected * cube, and rotate it along all three axes. * * Development environment specifics: * Arduino 1.0.5 * Arduino Pro 3.3V * Micro OLED Breakout v1.0 * * This code is beerware; if you see me (or any other SparkFun employee) at the * local, and you've found our code helpful, please buy us a round! * * Distributed as-is; no warranty is given. ******************************************************************************/ #include <Wire.h> // Include Wire if you're using I2C #include <SPI.h> // Include SPI if you're using SPI #include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library ////////////////////////// // MicroOLED Definition // ////////////////////////// #define PIN_RESET 9 // Connect RST to pin 9 #define PIN_DC 8 // Connect DC to pin 8 #define PIN_CS 10 // Connect CS to pin 10 #define DC_JUMPER 0 ////////////////////////////////// // MicroOLED Object Declaration // ////////////////////////////////// MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS); // SPI declaration //MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration void setup() { oled.begin(); // Initialize the OLED oled.clear(ALL); // Clear the display's internal memory oled.display(); // Display what's in the buffer (splashscreen) delay(1000); // Delay 1000 ms oled.clear(PAGE); // Clear the buffer. randomSeed(analogRead(A0) + analogRead(A1)); } void pixelExample() { printTitle("Pixels", 1); for (int i=0; i<512; i++) { oled.pixel(random(oled.getLCDWidth()), random(oled.getLCDHeight())); oled.display(); } } void lineExample() { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; int xEnd, yEnd; int lineWidth = min(middleX, middleY); printTitle("Lines!", 1); for (int i=0; i<3; i++) { for (int deg=0; deg<360; deg+=15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd); oled.display(); delay(10); } for (int deg=0; deg<360; deg+=15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); oled.display(); delay(10); } } } void shapeExample() { printTitle("Shapes!", 0); // Silly pong demo. It takes a lot of work to fake pong... int paddleW = 3; // Paddle width int paddleH = 15; // Paddle height // Paddle 0 (left) position coordinates int paddle0_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle0_X = 2; // Paddle 1 (right) position coordinates int paddle1_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle1_X = oled.getLCDWidth() - 3 - paddleW; int ball_rad = 2; // Ball radius // Ball position coordinates int ball_X = paddle0_X + paddleW + ball_rad; int ball_Y = random(1 + ball_rad, oled.getLCDHeight() - ball_rad);//paddle0_Y + ball_rad; int ballVelocityX = 1; // Ball left/right velocity int ballVelocityY = 1; // Ball up/down velocity int paddle0Velocity = -1; // Paddle 0 velocity int paddle1Velocity = 1; // Paddle 1 velocity //while(ball_X >= paddle0_X + paddleW - 1) while ((ball_X - ball_rad > 1) && (ball_X + ball_rad < oled.getLCDWidth() - 2)) { // Increment ball's position ball_X+=ballVelocityX; ball_Y+=ballVelocityY; // Check if the ball is colliding with the left paddle if (ball_X - ball_rad < paddle0_X + paddleW) { // Check if ball is within paddle's height if ((ball_Y > paddle0_Y) && (ball_Y < paddle0_Y + paddleH)) { ball_X++; // Move ball over one to the right ballVelocityX = -ballVelocityX; // Change velocity } } // Check if the ball hit the right paddle if (ball_X + ball_rad > paddle1_X) { // Check if ball is within paddle's height if ((ball_Y > paddle1_Y) && (ball_Y < paddle1_Y + paddleH)) { ball_X--; // Move ball over one to the left ballVelocityX = -ballVelocityX; // change velocity } } // Check if the ball hit the top or bottom if ((ball_Y <= ball_rad) || (ball_Y >= (oled.getLCDHeight() - ball_rad - 1))) { // Change up/down velocity direction ballVelocityY = -ballVelocityY; } // Move the paddles up and down paddle0_Y += paddle0Velocity; paddle1_Y += paddle1Velocity; // Change paddle 0's direction if it hit top/bottom if ((paddle0_Y <= 1) || (paddle0_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle0Velocity = -paddle0Velocity; } // Change paddle 1's direction if it hit top/bottom if ((paddle1_Y <= 1) || (paddle1_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle1Velocity = -paddle1Velocity; } // Draw the Pong Field oled.clear(PAGE); // Clear the page // Draw an outline of the screen: oled.rect(0, 0, oled.getLCDWidth() - 1, oled.getLCDHeight()); // Draw the center line oled.rectFill(oled.getLCDWidth()/2 - 1, 0, 2, oled.getLCDHeight()); // Draw the Paddles: oled.rectFill(paddle0_X, paddle0_Y, paddleW, paddleH); oled.rectFill(paddle1_X, paddle1_Y, paddleW, paddleH); // Draw the ball: oled.circle(ball_X, ball_Y, ball_rad); // Actually draw everything on the screen: oled.display(); delay(25); // Delay for visibility } delay(1000); } void textExamples() { printTitle("Text!", 1); // Demonstrate font 0. 5x8 font oled.clear(PAGE); // Clear the screen oled.setFontType(0); // Set font to type 0 oled.setCursor(0, 0); // Set cursor to top-left // There are 255 possible characters in the font 0 type. // Lets run through all of them and print them out! for (int i=0; i<=255; i++) { // You can write byte values and they'll be mapped to // their ASCII equivalent character. oled.write(i); // Write a byte out as a character oled.display(); // Draw on the screen delay(10); // Wait 10ms // We can only display 60 font 0 characters at a time. // Every 60 characters, pause for a moment. Then clear // the page and start over. if ((i%60 == 0) && (i != 0)) { delay(500); // Delay 500 ms oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left } } delay(500); // Wait 500ms before next example // Demonstrate font 1. 8x16. Let's use the print function // to display every character defined in this font. oled.setFontType(1); // Set font to type 1 oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left // Print can be used to print a string to the screen: oled.print(" !\"#$%&'()*+,-./01234"); oled.display(); // Refresh the display delay(1000); // Delay a second and repeat oled.clear(PAGE); oled.setCursor(0, 0); oled.print("56789:;<=>?@ABCDEFGHI"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("JKLMNOPQRSTUVWXYZ[\\]^"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("_`abcdefghijklmnopqrs"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("tuvwxyz{|}~"); oled.display(); delay(1000); // Demonstrate font 2. 10x16. Only numbers and '.' are defined. // This font looks like 7-segment displays. // Lets use this big-ish font to display readings from the // analog pins. for (int i=0; i<25; i++) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left oled.setFontType(0); // Smallest font oled.print("A0: "); // Print "A0" oled.setFontType(2); // 7-segment font oled.print(analogRead(A0)); // Print a0 reading oled.setCursor(0, 16); // Set cursor to top-middle-left oled.setFontType(0); // Repeat oled.print("A1: "); oled.setFontType(2); oled.print(analogRead(A1)); oled.setCursor(0, 32); oled.setFontType(0); oled.print("A2: "); oled.setFontType(2); oled.print(analogRead(A2)); oled.display(); delay(100); } // Demonstrate font 3. 12x48. Stopwatch demo. oled.setFontType(3); // Use the biggest font int ms = 0; int s = 0; while (s <= 5) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left if (s < 10) oled.print("00"); // Print "00" if s is 1 digit else if (s < 100) oled.print("0"); // Print "0" if s is 2 digits oled.print(s); // Print s's value oled.print(":"); // Print ":" oled.print(ms); // Print ms value oled.display(); // Draw on the screen ms++; // Increment ms if (ms >= 10) // If ms is >= 10 { ms = 0; // Set ms back to 0 s++; // and increment s } } // Demonstrate font 4. 31x48. Let's use the print function // to display some characters defined in this font. oled.setFontType(4); // Set font to type 4 oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left // Print can be used to print a string to the screen: oled.print("OL"); oled.display(); // Refresh the display delay(1000); // Delay a second and repeat oled.clear(PAGE); oled.setCursor(0, 0); oled.print("ED"); oled.display(); delay(1000); } void loop() { pixelExample(); // Run the pixel example function lineExample(); // Then the line example function shapeExample(); // Then the shape example textExamples(); // Finally the text example } // Center and print a small title // This function is quick and dirty. Only works for titles one // line long. void printTitle(String title, int font) { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; oled.clear(PAGE); oled.setFontType(font); // Try to set the cursor in the middle of the screen oled.setCursor(middleX - (oled.getFontWidth() * (title.length()/2)), middleY - (oled.getFontWidth() / 2)); // Print the title: oled.print(title); oled.display(); delay(1500); oled.clear(PAGE); } |
Comment préparer et afficher des images Bitmaps
Vous voudrez très certainement afficher plus qu’un simple texte sur votre petit écran. Voici deux solutions pour convertir vos Bitmaps en chaine Hexa.
LCD Assistant
LCD Assistant est un petit utilitaire bien pratique qui va vous permettre de convertir d’importe quel image au format Bitmap en un tableau de caractères pouvant être affiché sur votre mini écran OLED. LCD Assistant est recommandé par Sparkfun mais vous en trouverez d’autres sur internet avec les mots clés “convert bitmap to graphic lcd”.
Pour commencer vous devez disposer d’une image au format Bitmap. Après quelques tests, je vous conseil de redimensionner votre image pour quelle soit compatible avec l’écran cible. LCD Assistant est un programme bien pratique mais déjà ancien, il ne faut pas trop lui en demander et corriger à la main les petits défauts. J’ai pris pour cet exemple le logo de Projets DIY que j’ai redimensionné en 64 x 64 pixels (le logo est carré). Exportez l’image au format BMP monochrome. Si votre image dépasse la résolution demandée, elle sera tronquée et seule la partie en haut à gauche de l’image importée sera générée. J’ai obtenu le meilleur résultat en prenant la taille inférieure de 48×48 pixels.
Ouvrez l’image dans LCD Assistant en laissant 8 pixels/byte, orientation verticale pour Byte Orientation. Exportez le tableau via File -> Save Output. Donnez d’importe quel nom avec une extension .txt par exemple pour pouvoir ouvrir facilement le fichier avec un petit éditeur de texte. Vous obtiendrez une variable contenant votre image convertie. La conversion n’est pas toujours parfaite, bien souvent (toujours !!) vous devrez supprimer la première ligne du tableau [0x40, 0x00, 0x40, 0x00,] (attention de ne pas oublier la virgule).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
//------------------------------------------------------------------------------ // File generated by LCD Assistant // http://en.radzio.dxp.pl/bitmap_converter/ //------------------------------------------------------------------------------ const unsigned char icone [] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0x60, 0x60, 0x60, 0x60, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x08, 0x08, 0x08, 0x08, 0x08, 0xFF, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFF, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x04, 0x04, 0x04, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
Affichage d’un bitmap à l’aide de la librairie Sparkfun
On commence par nettoyer l’écran
1 |
oled.clear(ALL); |
En imaginant que votre écran OLED soit déclaré avec l’objet oled, il suffit d’appeler la fonction drawBitmap en lui passant en paramètre la variable contenant l’image à afficher.
1 |
oled.drawBitmap(bender); |
Maintenant on actualise l’écran. C’est tout
1 |
oled.display(); |
Affichage d’un bitmap avec la librairie Adafruit_GFX
La librairie Adafruit_GFX utilise une variable PROGMEM pour stocker l’image. La variable suivante a été générée à l’aide d’image2cpp présenté au prochain paragraphe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
const unsigned char myBitmap [] PROGMEM = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xf8, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xf8, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xf8, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x10, 0x08, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,}; |
Les commandes sont très similaires à celles de Sparkfun. On commence par nettoyer l’écran
1 |
display.clearDisplay() |
La commande drawBitmap nécessite les paramètres suivants : position x, position y, variable contenant le bitmap, largeur, hauteur, couleur. Pour mes tests, j’ai un écran de 128×32 pixels. Pour obtenir un logo carré, j’ai étendu l’image en doublant le nombre de pixels de x (64×32).
1 |
display.drawBitmap(32,0,myBitmap,64,32,WHITE); |
On actualise l’affichage
1 |
display.display(); |
Convertir une image bitmap en ligne avec Image2CPP
image2cpp est un outil de conversion de bitmap en chaine hexa pour afficheur LCD disponible en ligne à cette adresse http://javl.github.io/image2cpp/. image2cpp est beaucoup plus récent que LCD Assistant. image2cpp est aussi beaucoup plus puissant. Il vous permettra :
- De choisir une taille de génération différente du fichier image
- De choisir le mode de mise à l’échelle
- D’ajuster le niveau de gris de seuillage (Brightness threshold) entre le noir et le blanc si vos choisissez une image en couleur ou en niveau de gris.
- De re-centrer l’image verticalement et/ou horizontalement.
- D’inverser les couleurs
- D’ajouter du code Arduino qui définit la variable qu’il ne restera plus qu’à renommer après l’avoir collé dans votre code.
Un autre fonction très pratique et la possibilité de visualiser l’image qui sera produite par l’écran OLED en collant la chaine Hexa dans la zone “Paste byte array”. Par contre pour que cela fonctionne correctement, rechargez la page si vous aviez fait une conversion d’image avant.
Si vous avez un petit projet à réaliser et que vos trouvez que la programmation Arduino demande trop d’effort, le firmware ESP Easy permet d’afficher très simplement des informations sur un mini écran OLED. Il n’est pas possible d’afficher des images ou faire des animations, mais c’est suffisant pour débuter.
- Affichage OLED SSD1306 I2C sur Raspberry Pi. Code Python d’une mini station météo connectée à Jeedom avec la librairie Adafruit
- Déballage du clone Wemos ESP32 LoLin avec écran OLED monochrome 0.96” SSD1306 intégré
- Affichage OLED SSD1306 en MicroPython, exemple avec un baromètre numérique BME280 I2C
- Scanner WiFi portable à écran OLED (ESP8266) : force du signal, test de connection à un serveur
- #Test : Shield OLED pour Wemos D1 Mini (SSD1306 64×48 pixels) : ESP Easy et Adafruit_SSD1306
- Domoticz : script Lua pour créer un affichage déporté OLED avec ESP Easy