Thursday, 26 May 2016

Drive SSD1306 OLED with I2C on ESP8266 Wemos D1 mini

Bought some cheap and very small 128x64 OLEDs

They were initially in SPI Mode. For I2C some soldering has to be done: Move resistor R3 to R1 and bridge R8.


Two IO Pins are sufficient, if Res Pin goes with 100nF to ground and with 10k Resistor to 3.3V.


DC, CS are on ground.
With Micropython on a Wemos d1 mini:
import ssd1306
from machine import I2C, Pin
i2c = I2C(sda=Pin(4), scl=Pin(5))
display = ssd1306.SSD1306_I2C(64, i2c)
display.fill(0)
display.text('Hallo',20,20)
display.show()
view raw oled.py hosted with ❤ by GitHub

There is only one small font usable in micropython so I used the very good Adafruit_SSD1306 lib:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans24pt7b.h>
// No IO Pin for Reset nedded, if oled Res 100nF to ground and 10k to 3.3V
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
#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!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// init done
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setFont(&FreeSans24pt7b);
display.setCursor(5,32);
display.print(" 2:83");
display.display();
}
void loop() {
}
view raw oled.c hosted with ❤ by GitHub

No comments:

Post a Comment