adafruit_pcf8574

Python library for PCF8574 GPIO expander

  • Author(s): ladyada

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_pcf8574.DigitalInOut(pin_number: int, pcf: PCF8574)

Digital input/output of the PCF8574. The interface is exactly the same as the digitalio.DigitalInOut class, however:

  • PCF8574 does not support pull-down resistors

  • PCF8574 does not actually have a sourcing transistor, instead there’s an internal pullup

Exceptions will be thrown when attempting to set unsupported pull configurations.

Specify the pin number of the PCF8574 0..7, and instance.

property direction: Direction

Setting a pin to OUTPUT drives it low, setting it to an INPUT enables the light pullup.

property pull: digitalio.Pull.UP

Pull-up is always activated so always return the same thing

switch_to_input(pull: Pull | None = None, **kwargs) None

Switch the pin state to a digital input which is the same as setting the light pullup on. Note that true tri-state or pull-down resistors are NOT supported!

switch_to_output(value: bool = False, **kwargs) None

Switch the pin state to a digital output with the provided starting value (True/False for high or low, default is False/low).

property value: bool

The value of the pin, either True for high/pulled-up or False for low.

class adafruit_pcf8574.PCF8574(i2c_bus: I2C, address: int = 32)

Interface library for PCF8574 GPIO expanders :param ~busio.I2C i2c_bus: The I2C bus the PCF8574 is connected to. :param int address: The I2C device address. Default is 0x20

get_pin(pin: int) DigitalInOut

Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this PCF8574 device. :param int pin: pin to use for digital IO, 0 to 7

read_gpio() int

Read the full 8-bits of data from the GPIO register

read_pin(pin: int) bool

Read a single GPIO pin as high/pulled-up or driven low

write_gpio(val: int) None

Write a full 8-bit value to the GPIO register

write_pin(pin: int, val: bool) None

Set a single GPIO pin high/pulled-up or driven low