A small, thread-safe Python wrapper for the CAT9555 / TCA9555 16-bit I2C GPIO expander. It reads and writes the device's configuration, polarity, output and input registers over the I2C bus of any SBC (Raspberry Pi and similar).
Legacy module (2022). Kept for reference; docs refreshed in 2026, behavior unchanged.
Originally based on leloup314/TCA9555. CAT9555 datasheet: onsemi CAT9555.
- Read/write the 16-bit configuration, polarity, output and input registers.
- Thread-safe: I/O calls are serialized with a
threading.Eventlock. - Optional
logging.Loggerinjection. - Backed by smbus2, so it works on any SBC with I2C support.
- Python 3.6+ (uses type hints).
- An SBC with an I2C bus enabled.
smbus2.
pip install smbus2Then drop cat9555.py next to your code and import the class:
from cat9555 import CAT9555from cat9555 import CAT9555
# CAT9555 at address 0x24 on I2C bus 3. PORT0 is the MSB, PORT1 the LSB.
driver = CAT9555(i2c_port=3, address=0x24)
# Configure pin direction (1 = input, 0 = output).
driver.write_config(0x1eff)
# Invert polarity on all input pins.
driver.write_polarity(0xffff)
# Drive all outputs low.
driver.write_output(0x0000)
# Read back the registers.
config = driver.read_config()
iostate = driver.read_state()
polarity = driver.read_polarity()CAT9555(i2c_port=1, address=0x24, logger=None)
read_config() -> int # read configuration register
write_config(value: int) -> bool
read_polarity() -> int # read polarity inversion register
write_polarity(value: int) -> bool
write_output(value: int) -> bool # write output register
read_state() -> int # read input register (pin levels)
device_busy -> bool # True while an I/O call holds the lockwrite_* methods return True on success and False if the I2C transaction
raises. read_* methods return the 16-bit register value as an int.
MIT © 2022–2026 mdps
Un proyecto de mdps · 2026 · desarrollado en Murcia.