Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

"Input/output error" When stacking two IO Pluses

3377 Views - Created 24/07/2018


Posted by:

James_Bagley1 Avatar

I apologise in advance for not formatting code correctly but web browser won't play ball with "insert code snippet".

I have two IO plus stacked on my Raspberry Pi but when I try to make IO Ports by assigning I2C addresses 0x22 and 0x23 I get the following error message. The first IO Plus has its solder bridges unchanged but the second IO Plus has bus1 with the "2" bridge connected and bus2 has "2" and "0" bridges connected .

" File "/usr/local/lib/python3.4/dist-packages/IOPi/", line 117, in __init__
self.__ioaddress, self.IOCON, self.__ioconfig)
OSError: [Errno 5] Input/output error File "/usr/local/lib/python3.4/dist-packages/IOPi/", line 117, in __init__

self.__ioaddress, self.IOCON, self.__ioconfig)

OSError: [Errno 5] Input/output error"

My code is here, I would greatly appreciate any help:

#!/usr/bin/env python
ABElectronics IO Pi 32-Channel Port Expander - Tutorial 1

Requires python smbus to be installed
For Python 2 install with: sudo apt-get install python-smbus
For Python 3 install with: sudo apt-get install python3-smbus

run with: python

This example uses the write_pin and write_port methods to switch pin 1 on
and off on the IO Pi.
from __future__ import absolute_import, division, print_function, \
import time

from IOPi import IOPi
except ImportError:
print("Failed to import IOPi from python system path")
print("Importing from parent folder instead")
import sys
from IOPi import IOPi
except ImportError:
raise ImportError(
"Failed to import library from parent folder")

def main():

Main program function

# Initialise the first and second IO Plus as all outputs (32 outputs)
bus1 = IOPi(0x20)
bus2 = IOPi(0x21)
bus3 = IOPi(0x22)
bus4 = IOPi(0x23)

bus1.set_port_direction(0, 0x00)
bus1.set_port_direction(1, 0x00)
bus2.set_port_direction(0, 0x00)
bus2.set_port_direction(1, 0x00)
bus3.set_port_direction(0, 0x00)
bus3.set_port_direction(1, 0x00)
bus4.set_port_direction(0, 0x00)
bus4.set_port_direction(1, 0x00)

bus1.write_port(0, 0x00)
bus2.write_port(0, 0x00)
bus3.write_port(0, 0x00)
bus4.write_port(0, 0x00)
while True:
bus1.write_pin(3, 1)
bus1.write_pin(3, 0)

if __name__ == "__main__":


Posted by:

andrew Avatar

United Kingdom

andrew Twitter  andrew Website  

Hi James

An [Errno 5] Input/output error normally means the python code can not access the I2C port. Can you try running the following command and see what it returns?

sudo i2cdetect -y 1

It should show a list of I2C devices on your Raspberry Pi. If both IO Pi Plus boards are working then you should see 0x20, 0x21, 0x22, and 0x23.

If those numbers do not appear then there is a problem either with the I2C bus or the IO Pi Plus boards in which case it may be worth going through our I2C tutorial to make sure everything is configured correctly.


Posted by:

James_Bagley1 Avatar

Hi Andrew

I ran it like you said and it turns out the second IO Pi Plus was addressed as 0x24 and 0x25. Problem solved, thank you :)

Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.