# ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Tutorial 1 # Version 1.1 Created 10/05/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python tutorial1.py # ================================================ # This example uses the writePin and writePort methods to switch pin 1 on and off on the IO Pi. #!/usr/bin/python from ABElectronics_IOPi import IOPI import time bus = IOPI(0x21) bus.setPortDirection(0, 0x00) bus.writePort(0, 0x00) while True: bus.writePin(1, 1) time.sleep(1) bus.writePin(1, 0) time.sleep(1)
# Version 1.1 Created 30/04/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python iointerrupts.py # ================================================ # This example shows how to use the interrupt methods on the IO Pi. # The interrupts will be enabled and set so that a voltage applied to pins 1 and 16 will trigger INT A and B respectively. # using the readInterruptCature or readPort methods will reset the interrupts. # Initialise the IOPi device using the default addresses and set the output of bank 1 on IC1 to the input of bank 1 on IC2 bus1 = IOPI(0x20) bus2 = IOPI(0x21) # Set all pins on bus 2 to be inputs with internal pull-ups disabled. bus2.setPortPullups(0, 0x00) bus2.setPortPullups(1, 0x00) bus2.setPortDirection(0, 0xFF) bus2.setPortDirection(1, 0xFF) # Set the interrupt polarity to be active high and mirroring disabled, so pins 1 to 8 trigger INT A and pins 9 to 16 trigger INT B bus2.setInterruptPolarity(1) bus2.mirrorInterrupts(0) # Set the interrupts default value to trigger when 5V is applied to pins 1 and 16 bus2.setInterruptDefaults(0, 0x01) bus2.setInterruptDefaults(0, 0x80)
from ABElectronics_IOPi import IOPI import time import os # ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Input Read Demo # Version 1.1 Created 30/04/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python iopiread.py # ================================================ # This example reads the first 8 pins of bus 1 on the IO Pi board. The internal pull-up resistors are enabled so each pin will read as 1 unless the pin is connected to ground. # Initialise the IOPi device using the default addresses, you will need to change the addresses if you have changed the jumpers on the IO Pi bus1 = IOPI(0x20) # We will read the inputs 1 to 8 from bus 2 so set port 0 to be inputs and enable the internal pull-up resistors bus1.setPortDirection(0, 0xFF) bus1.setPortPullups(0, 0xFF) while True: # clear the console os.system('clear') # read the pins 1 to 8 and print the results print 'Pin 1: ' + str(bus1.readPin(1)) print 'Pin 2: ' + str(bus1.readPin(2)) print 'Pin 3: ' + str(bus1.readPin(3)) print 'Pin 4: ' + str(bus1.readPin(4)) print 'Pin 5: ' + str(bus1.readPin(5))
from ABElectronics_IOPi import IOPI import time # ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Output Write Demo # Version 1.1 Created 30/04/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python iopiwrite.py # ================================================ # This example uses the writePin and writeBank methods to switch the pins on and off on the IO Pi. # Initialise the IOPi device using the default addresses, you will need to change the addresses if you have changed the jumpers on the IO Pi bus1 = IOPI(0x20) # We will write to the pins 9 to 16 from bus 1 so set port 1 to be outputs turn off the pins bus1.setPortDirection(1, 0x00) bus1.writePort(1, 0x00) while True: # count to 255 and display the value on pins 9 to 16 in binary format for x in range(0, 255): time.sleep(0.05) bus1.writePort(1, x) # turn off all of the pins on bank 1 bus1.writePort(1, 0x00)
# ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Tutorial 1a # Version 1.1 Created 10/05/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python tutorial1a.py # ================================================ # This example uses the writePort method to count in binary using 8 LEDs #!/usr/bin/python from ABElectronics_IOPi import IOPI import time bus = IOPI(0x21) bus.setPortDirection(0, 0x00) bus.writePort(0, 0x00) while True: for x in range(0,255): bus.writePort(0, x) time.sleep(0.5) bus.writePort(0, 0x00)
# ================================================ # ABElectronics IO Pi 32-Channel Port Expander - Tutorial 1 # Version 1.1 Created 10/05/2014 # # Requires python smbus to be installed with: sudo apt-get install python-smbus # run with: sudo python tutorial1.py # ================================================ # This example uses the writePin and writePort methods to switch pin 1 on and off on the IO Pi. #!/usr/bin/python from ABElectronics_IOPi import IOPI import time bus = IOPI(0x21) bus.setPinDirection(1, 1) # set pin 1 as an input bus.setPinDirection(8, 0) # set pin 8 as an output bus.writePin(8,0) # turn off pin 8 bus.setPinPullup(1, 1) # enable the internal pull-up resistor on pin 1 bus.invertPin(1, 1) # invert pin 1 so a button press will register as 1 while True: