SH1106 OLED driver

Generic SH1106 display

Support is included in the SH1106 (About Modules) module, using the Graphics library.

The display shown can be set to operate in one of three modes by changing links on the pcb.

The modes are 4-wire SPI (with a D/C pin), 3-wire SPI, and I2C.

Other variants have only the I2C mode available, and 4 pins on the header: VCC, GND SDA & SCL.


SPI 3-wire isn't supported by this driver, only 4-wire is.

OLED pin Example pin on Espruino Board
VCC/3.3V 3.3V
DC B14
RST B10 (if you have this pin)
CE/CS B1 (if you have this pin - see the Software section for more info)


Just wire up as follows:

OLED pin Example pin on Espruino Board
VCC 3.3V
SDA (D1) B7
SCL (D0) B6
RST 3.3V (if you have this pin)
DC GND, address = 0x3C; 3.3V, address = 0x3D (if you have this pin)
CS GND or 3.3V, has no effect (if you have this pin)


function start(){
 // write some text
 g.drawString("Hello World!",2,2);
 // write to the screen

// I2C
var g = require("SH1106").connect(I2C1, start);

// SPI
var s = new SPI();
s.setup({mosi: B6 /* D1 */, sck:B5 /* D0 */});
var g = require("SH1106").connectSPI(s, A8 /* DC */, B7 /* RST - can leave as undefined */, start);

Note: This module uses a double buffer, which means you need to call g.flip() before any changes take effect.


By default the module is configured for 128x64 OLEDs. If you want to use 128x32 OLEDs, you must specify the height in the optional last argument. This has not yet been tried.

// I2C
require("SH1106").connect(I2C1, start, { height : 32 });
// SPI
require("SH1106").connectSPI(s, A8 /* DC */, B7 /* RST */, start, { height : 32 });

Chip Select (CS)

By default, chip select on the SPI OLEDs isn't used. You can however enable it with the following:

require("SH1106").connectSPI(s, A8 /* DC */, B7 /* RST */, start, { cs : MY_CS_PIN });

Non-standard I2C addresses

Some I2C modules are configured such that they aren't on the normal I2C address of 0x3C.

Also, if pin DC is tied to 3.3V.

If this is the case then you'll have to explicitly specify the address:

require("SH1106").connect(I2C1, start, { address : 0x3D });


You can set the contrast after initialisation using g.setContrast(31) with a value between 0 and 255.

However you can also set this at startup, using the options object:

require("SH1106").connect(I2C1, start, { 
  contrast : 31,


No tutorials use this yet.


This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.