bus.set_port_pullups(0, 0xFF) bus.set_port_pullups(1, 0xFF) bus.set_port_direction(0, 0xFF) bus.set_port_direction(1, 0xFF) # Inverting the ports will allow a button connected to ground to register as 1 or on. bus.invert_port(0, 0xFF) # invert port 0 so a button press will register as 1 bus.invert_port(1, 0xFF) # invert port 1 so a button press will register as 1 # Set the interrupt polarity to be active low and mirroring enabled, so # INT A and INT B go low when an interrupt is triggered bus.set_interrupt_polarity(0) bus.mirror_interrupts(1) # Set the interrupts default value to 0 so it will trigger when any of the pins on the bus change to 1 bus.set_interrupt_defaults(0, 0x00) bus.set_interrupt_defaults(1, 0x00) # Set the interrupt type to be 0xFF for ports A and B so an interrupt is # fired when the pin matches the default value bus.set_interrupt_type(0, 0xFF) bus.set_interrupt_type(1, 0xFF) # Enable interrupts for all pins on the bus bus.set_interrupt_on_port(0, 0xFF)
newbus = i2c_helper.get_smbus() bus1 = IoPi(newbus, 0x20) bus2 = IoPi(newbus, 0x21) # Set all pins on bus 2 to be inputs with internal pull-ups disabled. bus2.set_port_pullups(0, 0x00) bus2.set_port_pullups(1, 0x00) bus2.set_port_direction(0, 0xFF) bus2.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 bus2.set_interrupt_polarity(1) bus2.mirror_interrupts(0) # Set the interrupts default value to trigger when 5V is applied to pins 1 # and 16 bus2.set_interrupt_defaults(0, 0x01) bus2.set_interrupt_defaults(0, 0x80) # Set the interrupt type to be 1 for ports A and B so an interrupt is # fired when the pin matches the default value bus2.set_interrupt_type(0, 1) bus2.set_interrupt_type(1, 1) # Enable interrupts for pins 1 and 16 bus2.set_interrupt_on_pin(1, 1) bus2.set_interrupt_on_pin(16, 1)
newbus = i2c_helper.get_smbus() bus1 = IoPi(newbus, 0x20) bus2 = IoPi(newbus, 0x21) # Set all pins on bus 2 to be inputs with internal pull-ups disabled. bus2.set_port_pullups(0, 0x00) bus2.set_port_pullups(1, 0x00) bus2.set_port_direction(0, 0xFF) bus2.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 bus2.set_interrupt_polarity(1) bus2.mirror_interrupts(0) # Set the interrupts default value to trigger when 5V is applied to pins 1 # and 16 bus2.set_interrupt_defaults(0, 0x01) bus2.set_interrupt_defaults(0, 0x80) # Set the interrupt type to be 1 for ports A and B so an interrupt is # fired when the pin matches the default value bus2.set_interrupt_type(0, 1) bus2.set_interrupt_type(1, 1) # Enable interrupts for pins 1 and 16 bus2.set_interrupt_on_pin(1, 1) bus2.set_interrupt_on_pin(16, 1)