'IOError: [Errno 5] Input/output error' while using SMBus for analog reading through RPi 'IOError: [Errno 5] Input/output error' while using SMBus for analog reading through RPi python python

'IOError: [Errno 5] Input/output error' while using SMBus for analog reading through RPi


The cause to this might be that you're working remotely (SSH). After you disconnect the remote session, your program is still working and could try to print or interact to console, which is not available any more. This is what happened to me.


While this thread is old, I want to share my resuly hoping someone else might be helped as all posts I came across did not mention this potential fix.

I was encountering a similar issue, but with different hardware (MCP23017 and an LCD).

After chasing the problem for some time, I found the problem was not software, but rather hardware. Specifically the pull up resistors on the SCL and SDA lines.

The RPI (3 in my case) has 1.8k resistors and my LCD had some pull up resistors installed as well (~2.2k). Running the LCD never had a problem, but the MCP23017 would randomly disappear from the bus and reappear when running a scan by issuing command "i2cdetect -y 1".

Removing the extra pull up resistors on the LCD fixed the problem and all works perfectly now.


The cause to this might be that you're pushing out the read/write calls faster than your hardware can accept them. So add small delays between read/write operations:

from time import sleepfrom smbus import SMBusbus = SMBus(0)bus.write_byte(0x48, 0)sleep(0.2)  # Wait for device to actually settle downlastval = -1while True:  reada = bus.read_byte(0x48)  if(abs(lastval-reada) > 2):    print(reada)    lastval=reada  sleep(0.2) # This might be not needed.

Another possibility is that device is not actually present in this address. So if the timeouts don't help, try out i2c-tools (should be available via package management, unless you're using a custom software distribution) to check whether the device is actually available (sometimes it could be a wiring issue like forgotten GND):

i2cdetect -y [bus number]

Why i2c? Because SMBus is basically a modification of i2c bus with more strictly defined voltage levels and timings.