OsError Errno 5 while working with I2C

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
DieGT
Posts: 1
Joined: Sat Aug 20, 2022 9:33 pm

OsError Errno 5 while working with I2C

Post by DieGT » Sat Aug 20, 2022 9:39 pm

I am getting the following error in thonny while working with a RPI Pico and a Lcd 16x2 with I2C: Traceback (most recent call last):
File "<stdin>", line 12, in <module>
File "pico_i2c_lcd.py", line 22, in __init__
OSError: [Errno 5] EIO

I am using this youtube tutorial: https://www.youtube.com/watch?v=bXLgxEc ... l=NerdCave

:(

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OsError Errno 5 while working with I2C

Post by Roberthh » Sun Aug 21, 2022 7:40 am

Error 5 indicates a communication problem. The reason could be:

- wrong address
- connections problems.

For connection problems, check that

- all four wires are place: GND, SDA, SCL and Vcc
- there are pull-up resistors at SDA and SCL between SDA - Vcc and SDA - Vcc.
- The levels match. The Pico runs at 3.3V, LCD device typically have a 5V level. That can just work, given that all other parameter are fine.
- You used the wrong pins at the Pico. The Pin numbers used for the I2C object are GPIO numbers, nor board numbers. So Pin(4) is at board pin # 6.

If the wiring is fine, and assuming that SDA is at GPIO4 (board pin 6) and SCL at GPIO5 (board pin 7), you can check the connection with:

from machine import I2C, Pin
i2c = I2C(0, sda=Pin(4), scl=Pin(5))
print(i2c.scan())

i2c.scan() should return a short list with the device addresses on the bus. These are decimal numbers. If the list is either empty or very long, then there is still a wiring problem. If you get a short list, compare the returned numbers with the I2C address of your lcd device. If it is a matching one, use is.

Post Reply