Morning,
I'm a newb to this, so suspect i'm just doing something silly, or don't quite understand what i have written. Either way... here we go.
I have a Pi with an IO Pi Plus board attached (https://www.abelectronics.co.uk/p/54/io-pi-plus) and am attempting to utilise all the pins in Bus 1 to interface with some buttons i have wired up, from pin to ground.
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
'''
busin = IOPi(0x20)
# Set port 0 on the busin bus to be inputs with internal pull-ups enabled.
busin.set_port_pullups(0, 0xFF)
busin.set_port_direction(0, 0xFF)
# Invert the port so pins will show 1 when grounded
busin.invert_port(0, 0xFF)
# Set the interrupts default value for port 0 to 0x00 so the interrupt
# will trigger when any pin registers as true
busin.set_interrupt_defaults(0, 0x00)
# Set the interrupt type to be 1 on each pin for port 0 so an interrupt is
# fired when the pin matches the default value
busin.set_interrupt_type(0, 0xFF)
# Enable interrupts for all pins on port 0
busin.set_interrupt_on_port(0, 0xFF)
# Reset the interrupts
busin.reset_interrupts()
while True:
# read the interrupt status for each port.
if (busin.read_interrupt_status(0) != 0):
# If the status is not 0 then an interrupt has occured
# on one of the pins so read the value from the interrupt capture
value = busin.read_interrupt_capture(0)
# write the value to port 0 on the busout bus
print("button pressed: ", value)
# sleep 200ms before checking the pin again
time.sleep(0.2)
if __name__ == "__main__":
main()
This is the code i am running, now it seems that only pins 1 through 8 seem to give me a response, rather than pins 1 through 16 which is what i had expected. Wondered what i was doing wrong? sorry again, this is my first rodeo with python and the pi..
thanks
Andrew