You are here: Home / Hardware / OLED Display sh1106

OLED Display sh1106

i bought a chep oled display (~10 EUR) with 128x64 pixel. A SainSmart IIC OLED (IIC_1.3_OLED v.1), datasheet

Initially i thought it was a ssd1306 and tried to use it with the adafruit libraries. I ended with the u8glib which works fine.

Wiring

The display requires 3.3V power and 3.3 logic. Do not use 5V! If the arduino is directly powered by 3.3v we can connect the display to the same powersource. Otherwise a voltage regulator is required.

display arduino
3.3v vcc see above
gnd gnd
scl a5
sda a4
rst gpio4

i2c on esp8266

i2c is a software emulation on the esp8266. Any pair of gpio pins can be used, just assign them

Wire.pins(0, 2); // assign gpio 0 as sda and 2 as scl.

Checking

before trying to display any graphics, check if the device can be found on the i2c bus.

Get the i2c scanner sketch from the arduino playground. attached if it has vanished

Compile, flash. Open the serial monitor and somehting like this should show up

u8glib

https://github.com/olikraus/u8glib . It is available as package in the arduino ide. Menu -> sketch -> include library -> manage libaries

open any example sketch and comment out the correct header for the display

// this one works for me
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
// this is the safe but a bit slower version
// U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);

Display reset

to reset the display, the reset pin can be pulled.

#define RESET_PIN 4  // OLED reset pin
void oled_reset(void) {
  pinMode(RESET_PIN, OUTPUT);
  digitalWrite(RESET_PIN, HIGH);
  delay(1);
  digitalWrite(RESET_PIN, LOW);
  delay(10);
  digitalWrite(RESET_PIN, HIGH);
}