Support OLED2864 displays with reset pin
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__SKU_TOY0007_
Datasheet: https://image.dfrobot.com/image/data/TOY0007/SSD1306.pdf
SSD 1306 OLED (128x64) shows random dots
I have a custom SSD 1306 OLED (128x64) module connected to Esp32 through I2C.
I am able to find OLED using i2c.scan() method. (Address is 0x3d).
[An MPU9250 connected to same i2c also shows in i2c scan with address 0x68]
commands such as init_display(), poweroff(), poweron(), invert(), contrast() are working properly.
But I am unable to write texts, shapes etc.. on the screen. Only random dots are appearing.
Code:
import machine, ssd1306
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c, 0x3d)
oled.fill(0)
oled.text("Hello", 0, 0)
oled.text("Welcome to the", 0, 30)
oled.text("world of IoT", 0, 40)
oled.text(":)", 0, 50)
oled.show()