adafruit_pcf8575

CircuitPython library for Adafruit PCF8575 GPIO expander

  • Author(s): ladyada

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_pcf8575.DigitalInOut(pin_number: int, pcf: PCF8575)

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

  • PCF8575 does not support pull-down resistors

  • PCF8575 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 PCF8575 0..15, and instance.

Parameters:
  • pin_number (int) – The pin number

  • pfc (PCF8575) – The associated PCF8575 instance

property direction: Direction

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

property pull: Pull

Pull-up is always activated so this will always return the same, thing: digitalio.Pull.UP

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!

Note that keyword arguments are not parsed, and only included for compatibility with code expecting digitalio.DigitalInOut.

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).

Note that keyword arguments are not parsed, and only included for compatibility with code expecting digitalio.DigitalInOut.

Parameters:

value (bool) – The value to set upon switching to output; default is False

property value: bool

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

class adafruit_pcf8575.PCF8575(i2c_bus: I2C, address: int = 32)

Interface library for PCF8575 GPIO expanders

Parameters:
  • i2c_bus (I2C) – The I2C bus the PCF8575 is connected to.

  • address (int) – 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 PCF8575 device.

Parameters:

pin (int) – pin to use for digital IO, 0 to 15

read_gpio() int

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

read_pin(pin: int) bool

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

Parameters:

pin (int) – The pin number

write_gpio(val: int) None

Write a full 16-bit value to the GPIO register

Parameters:

val (int) – The value to write to the register

write_pin(pin: int, val: bool) None

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

Parameters:
  • pin (int) – The pin number

  • vale (bool) – The state to set