Page 1 of 1

OSError: [Errno 5] EIO while using I2C

Posted: Wed May 02, 2018 10:43 am
by nikhiledutech
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 ?

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

Posted: Wed May 02, 2018 3:38 pm
by fstengel
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.

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

Posted: Thu May 03, 2018 8:35 am
by nikhiledutech
Okay. I tried it, still it gives me same error.

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

Posted: Thu May 03, 2018 7:14 pm
by Frida
When it works from the terminal, try a little delay after your writing, so the eeprom has time to write.

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

Posted: Fri May 04, 2018 4:24 am
by nikhiledutech
I provided delay after write and it worked.

thankyou :)