micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.17k stars 7.68k forks source link

Support OLED2864 displays with reset pin #9001

Open jose1711 opened 2 years ago

jose1711 commented 2 years ago

OLED2864 is a module based on SSD1306 with I2C interface. Display initialization requires a Reset PIN to be wired and toggled, otherwise it won't react to I2C communication. Once this step is done it interfaces the same way as a standard SSD1306.

Here's a sample code:

# OLED2864 - RP2040
# SDA = GP0
# SCL = GP1
# D/C = GND
# VCC = 3.3V
# GND = GND
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
print(i2c.scan())

Output: [] (empty list - nothing was found on I2C bus).

Attempt to initialize display via display = ssd1306.SSD1306_I2C(128, 64, i2c) results in OSError: [Errno 5] EIO.

Working code (inspired by Adafruit SSD1306 library for Arduino) with Reset pin wired to GP2:

# ..
# RST = GP2
from machine import Pin, I2C
from utime import sleep_ms
import ssd1306

i2c = I2C(0, sda=Pin(0), scl=Pin(1))

reset_pin = Pin(2, Pin.OUT)
reset_pin.value(1)
sleep_ms(1)
reset_pin.value(0)
sleep_ms(10)
reset_pin.value(1)
print(i2c.scan())

display = ssd1306.SSD1306_I2C(128, 64, i2c)
display.text('foobar', 0, 0)
display.show()

Output: [60], display shows text.

This is what datasheet says about reset pin:

#RST
This pin is reset signal input. When the pin is pulled LOW, initialization of the chip is executed.
Keep this pin HIGH (i.e. connect to VDD ) during normal operation.

Seems that for the above mentioned OLED module (unlike similar I2C modules without Reset pin) such reset is mandatory. Therefore I think it would be nice ssd1306 module contains an optional parameter (reset_pin) which - if set - would perform such initialization when display object is being created.

Hardware: https://wiki.dfrobot.com/OLED_2864_display_module__SKUTOY0007 Datasheet: https://image.dfrobot.com/image/data/TOY0007/SSD1306.pdf

jonnor commented 3 days ago

The driver for ssd1306 is now found in https://github.com/micropython/micropython-lib/blob/394cbfc98a333dd1d4db35fb69379c72c30337f3/micropython/drivers/display/ssd1306/ssd1306.py#L30