MicroPython driver for SH1106 OLED Display
The driver contains the SH1106 class and the derived SH1106_I2C and SH1106_SPI classes. Besides the constructors, the methods are the same.
display = sh1106.SH1106_I2C(width, height, i2c, address)
- width and height define the size of the display in pixxels.
- i2c is an I2C object, which has to be created beforehand and tells the ports for SDA and SCL.
- adr is the I2C address of the display [default 0x3c].
display = sh1106.SH1106_SPI(width, height, spi, dc, res, cs)
- width and height define the size of the display in pixels.
- spi is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used.
- dc is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver.
- res is the GPIO Pin object for the reset connection. 'None' if not needed.
- cs is the GPIO Pin object for the CS connection. It can be set to 'None' or omitted.
frambuf is available as parameter which you can use. For example:
import framebuf fb = framebuf.FrameBuffer(bitmap_bytearray, 48, 64, framebuf.MONO_HLSB) display.framebuf.blit(fb, 40, 0) display.show()
from machine import Pin, I2C import sh1106 i2c = I2C(scl=Pin(22), sda=Pin(23)) display = sh1106.SH1106_I2C(128, 64, i2c) display.fill(0) display.text('OLED I2C TEST', 0, 0) display.show()
from machine import Pin, SPI import sh1106 spi = SPI(1, baudrate=1000000) display = sh1106.SH1106_SPI(128, 64, spi, Pin(22), Pin(23), Pin(4)) display.fill(0) display.text('OLED SPI TEST', 0, 0) display.show()