stlehmann / micropython-ssd1306

A fork of the driver for SSD1306 displays to make it installable via upip
MIT License
120 stars 41 forks source link

Fix for random garbage dots on the OLED #10

Open sheilbronn opened 9 months ago

sheilbronn commented 9 months ago

I would like to leave a note to folks also having the problem that the SSD1306 only displays random dots (=garbage). I had this problem on my HELTEC_Wifi_LoRa_32_v3 board banging my head for hours only to finally find and apply this simple fix from @piskernik

To fix one simply has to extend the class initialization with an explicit reset PIN parameter:

# extend ssd1306.py library:
...
class SSD1306_I2C(SSD1306):
    def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False, res=None):
        self.i2c = i2c
        self.addr = addr
        self.res = res
        self.temp = bytearray(2)
        self.write_list = [b"\x40", None]  # Co=0, D/C#=1
        if res != None:                 # NEW!
            res.init(res.OUT, value=0)
            import utime as time
            self.res(1)
            time.sleep_ms(1)
            self.res(0)
            time.sleep_ms(10)
            self.res(1)
        super().__init__(width, height, external_vcc)
...

and then to call it as follows (e.g. pin 21 on Heltec V3, could be pin 16 on other boards):

...
import ssd1306
oled = ssd1306.SSD1306_I2C(128, 64, i2c, res=Pin(21))
...

Here you can find more data about pins etc. .