[Errno 5] EIO - Day2 newbie struggling with I2C

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
twodoctors
Posts: 19
Joined: Tue Jun 28, 2022 11:24 am

[Errno 5] EIO - Day2 newbie struggling with I2C

Post by twodoctors » Tue Jun 28, 2022 11:42 am

Hi all,

Just bought my Pico kit yesterday, and loving it.

I'm playing with the codes and toys that came with it, and am struggling with the LC1602 display with a serial bus at the back.

I'm getting the Errno 5 EIO error and have no idea what it is, despite reading some of the answers here!

I'm going through the codes supplied with the kit line by line, and it hits the error at this stage:

Code: Select all

from machine import Pin, I2C, ADC
from time import sleep, sleep_ms
from machine_i2c_lcd import I2cLcd
import utime


i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000)

addr = i2c.scan()[0]
# print(hex(addr[0]))

lcd = I2cLcd(i2c, addr, 2, 16)
and the error says:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "machine_i2c_lcd.py", line 25, in __init__
OSError: [Errno 5] EIO
The machine_isc_lcd.py is again from the kit. Found here:

https://github.com/geeekpi/picokit/blob ... i2c_lcd.py

I've even tried a similar example from TomsHardware:

https://www.tomshardware.com/how-to/lcd ... ry-pi-pico

But same issue.

Hardware problem? Or have I missed something?

Thanks.

Adrian

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

Re: [Errno 5] EIO - Day2 newbie struggling with I2C

Post by Roberthh » Tue Jun 28, 2022 12:25 pm

One common misunderstanding with the Pico:
The Pin numbers mention with the I2C constructor (scl=Pin(9) ...) are GPIO numbers, not board pin numbers, So GPIO8 is board pin #11, GPIO9 is board pin #12.

i2c.scan() should return the I2C address of a device on the bus. If it does not, you still have a wiring problem.

twodoctors
Posts: 19
Joined: Tue Jun 28, 2022 11:24 am

Re: [Errno 5] EIO - Day2 newbie struggling with I2C

Post by twodoctors » Tue Jun 28, 2022 12:38 pm

Thanks for that Robert.

I restart the "project" again and plug everything in, and it's working!

Surprisingly though, when I didn't plug the SDA or SCL pin, the error is on the i2c.scan()[0] line, saying "list index out of range".

For my learning, what is Errno 5 EIO error, in plain English? :D remember I'm a newbie here!

Cheers

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

Re: [Errno 5] EIO - Day2 newbie struggling with I2C

Post by Roberthh » Tue Jun 28, 2022 12:45 pm

Errno 5 EIO error with I2C indicates a communication problem. Most of the time it is wrong wiring, but also may be caused by missing pull-up resistors.

The out-of-index error popped up, because i2c.scan() returns an empty list if it cannot find a device on the bus. And then there is no element with index [0].

twodoctors
Posts: 19
Joined: Tue Jun 28, 2022 11:24 am

Re: [Errno 5] EIO - Day2 newbie struggling with I2C

Post by twodoctors » Tue Jun 28, 2022 1:09 pm

So presumably whatever caused the Errno 5 initially is related to the I2C module, not miswiring... I mean even if I plug the wire in the wrong slots (which I'm sure I didn't!), I should have got an out-of-index error instead.

Very odd. Well, at least it's working now!

Thanks again.

Post Reply