OSError: [Errno 5] EIO while using I2C

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

OSError: [Errno 5] EIO while using I2C

Post by nikhiledutech » Wed May 02, 2018 10:43 am

Hello,

I am trying to write and read data from I2C based EEPROM. When i try the same code from the serial terminal it runs fine and it dont give me error.

But when i try to execute same code from main.py file i get the following OS Error "OSError: [Errno 5] EIO" .

Below i have given my code.

Code: Select all


from pyb import I2C, Pin

#I2C Initialisation 
i2c = I2C(1,I2C.MASTER, baudrate = 100000)

#Write data "A" to slave address 80 
i2c.mem_write("A",80,1,timeout = 5000, addr_size = 8)


#Recieve data into Recieve Buffer 
i2c.mem_read(1, 80, 1, timeout = 5000, addr_size = 8)

Have anyone faced the same issue, than please tell how to resolve it ?

fstengel
Posts: 30
Joined: Tue Apr 17, 2018 4:37 pm

Re: OSError: [Errno 5] EIO while using I2C

Post by fstengel » Wed May 02, 2018 3:38 pm

Have you tried inserting some delay between I2C initialization and its use? In the past, I had a similar problem on an ESP8266 and a small delay helped a lot. Your code would look like :

Code: Select all

from pyb import I2C, Pin
import utime

#I2C Initialisation 
i2c = I2C(1,I2C.MASTER, baudrate = 100000)

# And a short delay to wait until the I2C port has finished activating.
utime.sleep_ms(100)

#Write data "A" to slave address 80 
i2c.mem_write("A",80,1,timeout = 5000, addr_size = 8)
# Etc.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: OSError: [Errno 5] EIO while using I2C

Post by nikhiledutech » Thu May 03, 2018 8:35 am

Okay. I tried it, still it gives me same error.

User avatar
Frida
Posts: 38
Joined: Sat Jan 30, 2016 2:20 pm
Location: Middelfart, Denmark

Re: OSError: [Errno 5] EIO while using I2C

Post by Frida » Thu May 03, 2018 7:14 pm

When it works from the terminal, try a little delay after your writing, so the eeprom has time to write.
Yes Frida is my watchdog!

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: OSError: [Errno 5] EIO while using I2C

Post by nikhiledutech » Fri May 04, 2018 4:24 am

I provided delay after write and it worked.

thankyou :)

Post Reply