SSD1306 very slow

Hi there,

I tried out the SSD1306 drivers from the latest release on an ESP32 connected to a 128x64 OLED display over I2C running at 400 kHz.

I noticed that it is extremely slow to write text to the display. I’d say each row takes around a second or so.

Anyone else experiencing the same behaviour?

I’m new in using Python with microcontrollers (I’ve been using C a lot) and naturally have doubts about how fast things are with the VM. It would be interesting to understand if this delay comes from the library itself or inherently from the VM.

Hi @nickagian
In general, The VM layer adds some delay only during some python operations that are resource intensive.
But if you are using the streams library for example then it just calls the appropriate serial drivers, so there is no overhead/delay due to the python layer.
You can try some examples in python such as threading, interrupts, Timers, You’ll notice minimal (if any) delay.
For optimal performance, develop your time critical code in C as in C language interface example.

As for the SSD1306 Oled, I tested its driver on my Heltec Wi-Fi Kit 32 that has the 1306 OLED onboard.
The driver seems to be working normally, the official examples of the library has some sleep() methods, you can try deleting them.

For instance, try this example and let me know the performance.

import streams
streams.serial()

print("import")
sleep(1000)

from solomon.ssd1306 import ssd1306

print("start")
sleep(1000)

try:
    # Setup display 

    # The ssd1306 can use either the spi or the i2c interface
    # the flag SSD1306SPI enables the spi interface
    # the flag SSD1306I2C enables the i2c interface
    # those two flags can't be set both to true 

    ssd = None

    #-if SSD1306SPI
    # This setup is referred to ssd1306 mounted on slot A of a Flip n Click device
    #ssd = ssd1306.SSD1306(SPI0,D17,D16,D6)
    #-else
    ##-if SSD1306I2C
    # This setup is referred to ssd1306 mounted on a XinaBox CW02
    ssd = ssd1306.SSD1306(I2C0,rst=D16)
    ##-endif
    #-endif
except Exception as e:
    print("Error1", e)
    
ssd.init()
ssd.on()


while True:
    try:
        a = random(0,10)
        ssd.clear()
        ssd.draw_text(str(a),0,0,96,12, align=2)
        ssd.draw_text(str(a),0,14,96,12, align=2)
        ssd.draw_text(str(a),0,28,96,12, align=2)
        ssd.fill_screen()
        
    except Exception as e:
        print(e)