# Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library # # Requires python smbus to be installed with: sudo apt-get install python3-smbus # run with: sudo python3 demo-iointerrupts.py # ================================================ # This example shows how to use the interrupt methods on the Expander Pi IO port. # 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 read_interrupt_capture or read_port methods will reset the # interrupts. # Initialise the IOPi and create an instance called io. """ io = IO() # Set all pins on the IO bus to be inputs with internal pull-ups disabled. io.set_port_pullups(0, 0x00) io.set_port_pullups(1, 0x00) io.set_port_direction(0, 0xFF) io.set_port_direction(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 io.set_interrupt_polarity(1) io.mirror_interrupts(0) # Set the interrupts default value to trigger when 5V is applied to pins 1 # and 16
================================================ ABElectronics Expander Pi | Digital I/O Interrupts Demo Version 1.0 Created 21/08/2014 Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library Requires python smbus to be installed with: sudo apt-get install python3-smbus run with: sudo python3 demo-iowrite.py ================================================ This example uses the write_pin and writeBank methods to switch the pins on and off on the I/O bus. Initialise the IO class and create an instance called io. """ io = IO() # We will write to the pins 9 to 16 so set port 1 to be outputs turn off # the pins io.set_port_direction(1, 0x00) io.write_port(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) io.write_port(1, x) # turn off all of the pins on bank 1 io.write_port(1, 0x00)
import time import os # ================================================ # ABElectronics Expander Pi | Tester # Version 1.0 Created 08/11/2014 # Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library # # run with: python tester.py # ================================================ # This script tests the various functionality of the Expander Pi rtc = RTC() # create a new instance of the RTC class adc = ADC() # create an instance of the ADC class io = IO() # create an instance of the IO class dac = DAC(1) # create an instance of the DAC class with a gain of 0 # set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS rtc.set_date("2017-01-01T00:00:00") dac.set_dac_voltage(1, 1.5) # set the voltage on channel 1 to 1.5V dac.set_dac_voltage(2, 1.0) # set the voltage on channel 2 to 1.0V # set the reference voltage. this should be set to the exact voltage # measured on the Expander Pi Vref pin. adc.set_adc_refvoltage(4.096) while True: # clear the console os.system('clear')
Version 1.0 Created 21/08/2014 Requires python smbus to be installed with: sudo apt-get install python-smbus run with: sudo python demo-iowrite.py ================================================ This example uses the write_pin and writeBank methods to switch the pins on and off on the I/O bus. Initialise the IO class and create an instance called io. """ i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() io = IO(bus) # We will write to the pins 9 to 16 so set port 1 to be outputs turn off # the pins io.set_port_direction(1, 0x00) io.write_port(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) io.write_port(1, x) # turn off all of the pins on bank 1 io.write_port(1, 0x00)
ABElectronics Expander Pi | Digital I/O Interrupts Demo Version 1.0 Created 21/08/2014 Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library Requires python smbus to be installed with: sudo apt-get install python3-smbus run with: sudo python3 demo-ioread.py ================================================ This example reads the first 8 pins of on the Expander Pi Digital I/O port. The internal pull-up resistors are enabled so each pin will read as 1 unless the pin is connected to ground. Initialise the IO class and create an instance called io. """ io = IO() # We will read the inputs 1 to 16 from the I/O bus so set port 0 and port 1 to be # inputs and enable the internal pull-up resistors io.set_port_direction(0, 0xFF) io.set_port_pullups(0, 0xFF) io.set_port_direction(1, 0xFF) io.set_port_pullups(1, 0xFF) while True: # clear the console os.system('clear') # read the pins 1 to 16 and print the results print ('Pin 1: ' + str(io.read_pin(1)))
intA = io.read_interrupt_status(0) # reset the interrupts io.reset_interrupts() # check the value of intA to see if an interrupt has occurred if (intA != 0): callback_function() # sleep this thread for 0.5 seconds time.sleep(0.5) i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() io = IO(bus) # Set all pins on the IO bus to be inputs with internal pull-ups enabled. io.set_port_pullups(0, 0xFF) io.set_port_pullups(1, 0xFF) io.set_port_direction(0, 0xFF) io.set_port_direction(1, 0xFF) # invert the ports so pulling a pin to ground will show as 1 instead of 0 io.invert_port(0, 0xFF) io.invert_port(1, 0xFF) # Set the interrupt polarity to be active high and mirroring enabled, so # pin 1 will trigger both INT A and INT B when a pin is grounded io.set_interrupt_polarity(1)
ABElectronics Expander Pi | Digital I/O Interrupts Demo Version 1.0 Created 29/03/2015 run with: python3 demo-ioread.py ================================================ This example reads the first 8 pins of on the Expander Pi Digital I/O port. The internal pull-up resistors are enabled so each pin will read as 1 unless the pin is connected to ground. Initialise the IO class and create an instance called io. """ i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() io = IO(bus) # We will read the inputs 1 to 8 from the I/O bus so set port 0 to be # inputs and enable the internal pull-up resistors io.set_port_direction(0, 0xFF) io.set_port_pullups(0, 0xFF) while True: # clear the console os.system('clear') # read the pins 1 to 8 and print the results print ('Pin 1: ' + str(io.read_pin(1))) print ('Pin 2: ' + str(io.read_pin(2))) print ('Pin 3: ' + str(io.read_pin(3))) print ('Pin 4: ' + str(io.read_pin(4)))
# reset the interrupts io.reset_interrupts() # check the value of intA to see if an interrupt has occurred if (intA != 0): callback_function() # sleep this thread for 0.5 seconds time.sleep(0.5) i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() io = IO(bus) # Set all pins on the IO bus to be inputs with internal pull-ups enabled. io.set_port_pullups(0, 0xFF) io.set_port_pullups(1, 0xFF) io.set_port_direction(0, 0xFF) io.set_port_direction(1, 0xFF) # invert the ports so pulling a pin to ground will show as 1 instead of 0 io.invert_port(0,0xFF) io.invert_port(1,0xFF) # Set the interrupt polarity to be active high and mirroring enabled, so # pin 1 will trigger both INT A and INT B when a pin is grounded io.set_interrupt_polarity(1)
ABElectronics Expander Pi | Digital I/O Interrupts Demo Version 1.0 Created 21/08/2014 Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library Requires python smbus to be installed with: sudo apt-get install python3-smbus run with: sudo python3 demo-ioread.py ================================================ This example reads the first 8 pins of on the Expander Pi Digital I/O port. The internal pull-up resistors are enabled so each pin will read as 1 unless the pin is connected to ground. Initialise the IO class and create an instance called io. """ io = IO() # We will read the inputs 1 to 16 from the I/O bus so set port 0 and port 1 to be # inputs and enable the internal pull-up resistors io.set_port_direction(0, 0xFF) io.set_port_pullups(0, 0xFF) io.set_port_direction(1, 0xFF) io.set_port_pullups(1, 0xFF) while True: # clear the console os.system('clear') # read the pins 1 to 16 and print the results print('Pin 1: ' + str(io.read_pin(1)))
import os # ================================================ # ABElectronics Expander Pi | Tester # Version 1.0 Created 29/03/2015 # # run with: python3 tester.py # ================================================ # This script tests the various functionality of the Expander Pi i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() rtc = RTC(bus) # create a new instance of the RTC class adc = ADC() # create an instance of the ADC class io = IO(bus) # create an instance of the IO class dac = DAC() # create an instance of the DAC class # set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS rtc.set_date("2014-01-01T00:00:00") dac.set_dac_voltage(1, 1.5) # set the voltage on channel 1 to 1.5V dac.set_dac_voltage(2, 1.0) # set the voltage on channel 2 to 1.0V # set the reference voltage. this should be set to the exact voltage # measured on the Expander Pi Vref pin. adc.set_adc_refvoltage(4.096) while True: # clear the console os.system('clear')