About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

"Input/output error" When stacking two IO Pluses

1190 Views - Created 24/07/2018

24/07/2018

Posted by:
James_Bagley1

Users 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/IOPi.py", 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/IOPi.py", 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 tutorial1.py
================================================

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, \
                                                    unicode_literals
import time

try:
    from IOPi import IOPi
except ImportError:
    print("Failed to import IOPi from python system path")
    print("Importing from parent folder instead")
    try:
        import sys
        sys.path.append("..")
        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)
        time.sleep(2)
        bus1.write_pin(3, 0)
        time.sleep(2)
  
        
if __name__ == "__main__":
    main()

 

24/07/2018

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users 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, 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.

AB Electronics UK Tech Support

25/07/2018

Posted by:
James_Bagley1

Users 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 :)

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.