
There are many 128×64 or 128×32 monochrome OLED display out, and recently, I’ve seen tiny 64×32 dot OLED display sold.
However, library such as Adafruit SSD1306 does not support this resolution at this time. Either find library which support tiny display, or make modification to library.
I’ve modifed Adafruit SSD1306 library (version 2.2.0) to use with 64×32 OLED display.
Modifications are 2 part in Adafruit_SSD1306.cpp file. Around line 549 and 888, add / modify for 64×32 resolution. Since I simply replaced code near line 888, this library won’t be compatible with other resolution.
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | if ((WIDTH == 128 ) && (HEIGHT == 32 )) { comPins = 0x02 ; contrast = 0x8F ; } else if ((WIDTH == 128 ) && (HEIGHT == 64 )) { comPins = 0x12 ; contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF ; } else if ((WIDTH == 96 ) && (HEIGHT == 16 )) { comPins = 0x2 ; // ada x12 contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x10 : 0xAF ; } else if ((WIDTH == 64 ) && (HEIGHT == 32 )) { comPins = 0x12 ; contrast = (vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF ; } else { // Other screen varieties -- TBD } |
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | void Adafruit_SSD1306::display( void ) { TRANSACTION_START /* static const uint8_t PROGMEM dlist1[] = { SSD1306_PAGEADDR, 0, // Page start address 0xFF, // Page end (not really, but works here) SSD1306_COLUMNADDR, 0 }; // Column start address ssd1306_commandList(dlist1, sizeof(dlist1)); ssd1306_command1(WIDTH - 1); // Column end address*/ static const uint8_t PROGMEM dlist1[] = { SSD1306_PAGEADDR, 0 , // Page start address 0xFF , // Page end (not really, but works here) SSD1306_COLUMNADDR, 0x20 }; // Column start address ssd1306_commandList(dlist1, sizeof(dlist1)); ssd1306_command1( 0x20 + (WIDTH - 1 )); // Column end address |
Simple Hello World sample sketch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <Wire.h> #include <SPI.h> #include <Adafruit_GFX.h> #include "Adafruit_SSD1306.h" #define SCREEN_WIDTH 64 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, - 1 ); void setup() { Wire.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C ); // initialize with the I2C addr display.clearDisplay(); display.setTextSize( 1 ); display.setTextColor(WHITE); display.setCursor( 0 , 5 ); display.print( "Hello\n World" ); display.display(); } void loop() { } |
Below includes sample sketch with modified library.
Also, I’ve modified ESP_Adafruit_SSD1306 library to use with ESP8266.
This post is also available in: Japanese