PCF8574 input driver

It works with PCF8574 IO expanders. You can see an guide on modifying them and connecting them to buttons & I2C here.

class input.drivers.pcf8574.InputDevice(addr=39, bus=1, int_pin=None, **kwargs)[source]

A driver for PCF8574-based I2C IO expanders. They have 8 IO pins available as well as an interrupt pin. This driver treats all 8 pins as button pins, which is often the case.

It supports both interrupt-driven mode (as fr now, RPi-only) and polling mode.

__init__(addr=39, bus=1, int_pin=None, **kwargs)[source]

Initialises the InputDevice object.


  • bus: I2C bus number.
  • addr: I2C address of the expander.
  • int_pin: GPIO pin to which INT pin of the expander is connected. If supplied, interrupt-driven mode is used, otherwise, library reverts to polling mode.

Interrupt-driven loop. Currently can only use RPi.GPIO library. Stops when stop_flag is set to True.


Polling loop. Stops when stop_flag is set to True.


Checks data received from IO expander and classifies changes as either “button up” or “button down” events. On “button up”, calls send_key with the corresponding button name from self.mapping.


Starts listening on the input device. Initialises the IO expander and runs either interrupt-driven or polling loop.