Search code examples
pythonmicropythonraspberry-pi-pico

How to fix "OSError: [Errno 110] ETIMEDOUT" error in thonny ide


My code is made using raspberry pi pico and oled (ssd1306) and it is like this:

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
width = 128
height = 64
i2c = I2C(1, scl=Pin(15), sda=Pin(14), freq=400000)
oled = SSD1306_I2C(width, height, i2c)
oled.fill(0)
oled.text("Hola perro", 5, 8)
oled.text("2022", 5, 18)
oled.show()

and error:

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "ssd1306.py", line 118, in __init__
  File "ssd1306.py", line 37, in __init__
  File "ssd1306.py", line 74, in init_display
  File "ssd1306.py", line 123, in write_cmd
OSError: [Errno 110] ETIMEDOUT

And if I add print(i2c.scan()) to my program it shows me this:

>>> print(i2c.scan())
[]

Solution

  • I have got your code working. The problem was the pin numbers. The numbers supplied in the code should be the GPIO numbers not the physical numbers of the pins.

    So this worked:

    i2c = I2C(0, scl=Pin(21), sda=Pin(20), freq=400000)
    

    with SCL on GP21 (physical pin 27) and SDA on GP20 (physical pin 26). Note the first parameter of my code is 0 because I am using I2C zero.