Getting IOError: [Errno 121] Remote I/O error with smbus on python (raspberry) while trying to get data over I2C from Arduino

Getting IOError: [Errno 121] Remote I/O error with smbus on python (raspberry) while trying to get data over I2C from Arduino

I solved it!!

I got a hint from this post:
https://www.raspberrypi.org/forums/viewtopic.php?t=203286

By adding a delay after bus = smbus.SMBus(1) solved this issue.
It seems that a short delay is somehow needed so that the I2C can settle.

Working Code tested by calling script 100times without issues.

import smbus
import time
bus = smbus.SMBus(1)
time.sleep(1) #wait here to avoid 121 IO Error
while True:
    data = bus.read_i2c_block_data(0x04,0x02,4)
    result = 0
    for b in data:
        result = result * 256 + int(b)
    print(result)
    time.sleep(1)

Getting IOError: [Errno 121] Remote I/O error with smbus on python (raspberry) while trying to get data over I2C from Arduino

Leave a Reply

Your email address will not be published.