mcauser / micropython-ssd1327

MicroPython driver for SSD1327 128x128 4-bit greyscale OLED displays
MIT License
25 stars 10 forks source link

Rpi Pico HW i2c initialization problem #6

Open dingo27mobile opened 10 months ago

dingo27mobile commented 10 months ago

Hello Mike,

i am trying to initialize this with HS i2c in RPi Pico, but no success, only on SW... i have 128x128 display, with SW it works ok, but slow in samples and documentation i cannot see how to tell in code which i2c pins i am using.

import ssd1327 from machine import I2C, Pin i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000) display = ssd1327.SSD1327_I2C(128, 128, i2c)

with this it shows -> Traceback (most recent call last): File "", line 4, in File "ssd1327.py", line 178, in init File "ssd1327.py", line 78, in init File "ssd1327.py", line 113, in init_display File "ssd1327.py", line 186, in write_data OSError: [Errno 110] ETIMEDOUT

is there error in library, or my code... ?

mcauser commented 10 months ago

Possibly related to https://github.com/mcauser/micropython-ssd1327/issues/5

According to the RP2 docs, that looks like the correct way to init HW I2C. https://docs.micropython.org/en/latest/rp2/quickref.html#hardware-i2c-bus

Maybe try reducing the freq? Or try I2C1 pins?

i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=200000)
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=100000)

i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq=400000)
i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq=200000)
i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq=100000)

Next time I have my Pico handy, I'll try to replicate and update the docs with a working HW I2C config.

dingo27mobile commented 10 months ago

The initialization works for other i2c device (bme280), i literally copied it from working code.

i also tried your suggestion of slower i2c / different pins, but same error occurs.

Seems there might be bug in this library, but i cannot tell for sure.

mcauser commented 10 months ago

The OSError suggests the display was not found on the I2C bus. If you perform an i2c.scan(), can you see a 60 / 0x3C?

dingo27mobile commented 10 months ago

yes, the "i2c.scan()" prints 60.

gigagoex commented 8 months ago

Hi @mcauser are you still working on this lib? I observed the same error. For me, your library works with SoftI2c but not with hardware I2c. The error appears when calling i2c.writevto in def write_data(self, data_buf): self.data_list[1] = data_buf self.i2c.writevto(self.addr, self.data_list) Edit: Found the issue: the TIMEDOUT error was caused by the size of the list of an 128x128 display. On the pico I measured ~205 µs for writing the list at a frequency of 400 kHz. Therefore, I had to set the I2C timeout accordingly. Now it works as expected!

mcauser commented 4 months ago

Thanks for the feedback. I've been mainly using this with ESP32's. I'll do some testing with Pis before my next release.