adafruit / Adafruit_CircuitPython_HT16K33

Adafruit CircuitPython driver for the HT16K33, a LED matrix driver IC.
MIT License
41 stars 30 forks source link

super slow update on raspberry pi pico W #115

Open jkozniewski opened 10 months ago

jkozniewski commented 10 months ago

Hello

I've observed very slow display update for 14-segement backpack (https://www.adafruit.com/product/1910) controlled by raspberry pi pico W (using latest circuit python uf2)

According to the test code provided below update of all 4 characters takes about 13-14 ms and scales more or less linearly with each new character added ( the single call of display.set_digit_raw takes about 3-4 ms ) which makes integrating this display pretty hopeless for any code that needs to update something else quickly as the code is blocking, especially if someone want's to chain a few of those...

import board
import busio
from adafruit_ht16k33 import segments
import supervisor

i2c = busio.I2C(board.GP21, board.GP20)
display = segments.Seg14x4(i2c)

start_msecs = supervisor.ticks_ms()
display.print("ABCD")
stop_msecs = supervisor.ticks_ms()

print("elapsed time = ", stop_msecs - start_msecs)

Wondering what might be the reason for such slow I2C implementation - is it pico W related or circuit python in general ? I have tested the displays with regular Arduino UNO and your library (https://github.com/adafruit/Adafruit_LED_Backpack) and the equivalent update (4 characters via writeDigitRaw()) takes only 1 ms, or 1850 micro seconds, if simple micros() before-after measurement can be trusted.

Any insights and ideas how to overcome this are much appreciated !

jkozniewski commented 10 months ago

Ok Investigated some further and tried with vanilla micropython (v1.22.1) uf2, using https://github.com/smittytone/HT16K33-Python library. Here updating one character takes less than 1 ms (with 6 of backpacks chained I get 6-8 ms for updating all 24 chars). So it points to some not-so-optimal implementation of I2C in circuit python / HT16K33 lib itself... Still - hope it can be improved in near future :) !