SH 1106 Display and SSD1306 and …

in the bottom some examples with source

A very common used display for small systems is monochrome LED displayss

 
  • 128 x 32 0.91" OLED

  • I2C interface

  • driver chip SSD1306

  • 3.3-5V

 
  • 128 x 64 1.3" OLED

  • SPI(I2C) interface

  • driver chip SH1106

  • 3.3-5V

Just these two similar displays use same driver but with different configuration

 
  • 128 x 64 1.3" OLED based on sh1106

  • 128 x 32 0.91 OLED based on ssd1306

  • NODEMCU

Driver install

We will use the U8g2 library

NB YOU can also use the same library install for the 0.91 SSD1306 display

You can install it in your Arduino IDE

  1. Start Arduino IDE

  2. NODEMCU ESP32 (important its an ESP32)

  3. Go to Sketch->include library-> manage libraries

  4. Seek for U8g2 liubrary

  5. Install it

Not one but two libraries in One

U8g2 has one small efficient library to be used on systems with little memory and the one large and withmore features

So you have to select which one you will use.

On an ESP32 I will prefer U8g2.

In all cases you need as first part in your program to have following code

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

It includes interface to the drivers.

Configuration of which library and display

You configure the library in your own code

  • pins connection

  • which library you use u8x8 or U8g2lib

  • SPI og I2C/TWI on back on the display - requires soldering

Pins

... using SPI interface ...

On my NodeMCU ESP32 I have connected to my 128x64 sh1106 display

   Display    ESP32
   ------------------------

   GND        GND (ground)
   VCC        3.3V or Vin
   CLK        GPIO18
   MOSI       GPIO23
   RES        GPIO17
   DC         GPIO22
   CS         GPIO5

u8x8 usage

For configure you need to create an u8x8 object or variable with the right configuration (pins) as a globale objecxt/variable in your code

// JDN
//              object type            name                                   parameters
//         ----- \/-------             --\/--      ---------------------------  \/-------------------------
//JDN
//U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8x8 (/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

I use

U8X8_SH1106_128X64_NONAME_4W_HW_SPI  u8x8 ( 5,22,17);
//JDN


CLK:  SPI clock
MOSI: Master Out Slave In - data/command stream from master(ESP32) to slave(display)
DC:  Select data/command (SPI)
CS:  Chip select (SPI)
RES: Reset displays

Is you use other pins then change

Check available ESP32 pins at here

A simple u8x8 hello world progam

A very simple Hello World program usin u8x8 library. Check lines marked JDN

(click for helloworld using u8x8lib - look for JDN)

u8x8.setPowerSave(0); is nice to know - turn on display

U8g2

Basicly same as the u8x8 examples

... using SPI interface ...

On my NodeMCU ESP32 I have connected to my 128x64 ssh1106 display

   Display    ESP32
   ------------------------

   GND        GND (ground)
   VCC        3.3V or Vin
   CLK        GPIO18
   MOSI       GPIO23
   RES        GPIO17
   DC         GPIO22
   CS         GPIO5

An U8g2 program

Lets tak a look into U8g2Logo found in examples->U8gs->page_buffer->U8g2Logo

You need to have following line uncommmented and with correct pins

Note that the var/object name is now u8g2
In the hello world is was ux8x

//JDN
// NB _F_ means framebuffer so you can use clearBuffer and sendBuffer - otherwise your are stucked withmore firstPage and nextPage
// no framebuffer replace _F_ with  _1_  below
//
//U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI u8g2  (U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI   u8g2  (U8G2_R0,     5,           22,           17);
//JDN

U8g2 Framebuffer issue with or without

NB NB You have to decide with or without framebuffer- framebuffer should more efficient but also take a small amount on RAM. This might be an issue on an UNO but not on an esp32

Framebuffer is a local copy of the moery on the graphical controller. Then write text, pixels etc and then you transfer the image to the controller by sendBuffer. Can be more efficient bq every graphic call directly in memory takes less time compared to move pixel by pixel to the ssh 1106 controller on the display.

Config for my NODEMCU ESP32

You can see type starts with U8G2_ - so we are using the U8g2 library

>>>> without framebuffer
U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI   u8g2  (U8G2_R0,     5,           22,           17);

void setup()
{
  u8g2.begin();
}

void loop(void) {

  u8g2.firstPage();

  do {
     u8g2.drawPixel(3,3);
  } while ( u8g2.nextPage() );

  delay(10);
}

>>>> with framebuffer
>>>> I USE THIS ONE - You can see there is a _F_ in type ame

U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI   u8g2  (U8G2_R0,     5,           22,           17);

void setup()
{
  u8g2.begin();
}

void loop(void) {

  u8g2.clearBuffer();  // if you want to clear buffer otherwise just add to buffer
  u8g2.drawPixel(3,3);
  u8g2.sendBuffer();

  delay(10);
}

A simple U8g2 logo program

(click for U8g2Logo using U8g2 lib - look for JDN)

start on a pong program

(click for pong start )

start on a tripple watch

(click for watch ino code )

start on a pong or snake program

(click for pong/snake )

start on a snake w tail program

(click for pong/snake w tail )

Simple drawing text in u8x8

(click for helloworld using u8x8lib)