Skip to content
This repository was archived by the owner on Jun 23, 2026. It is now read-only.

SubniC/python-cat9555

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CAT9555 / TCA9555 Python driver

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.

Features

  • Read/write the 16-bit configuration, polarity, output and input registers.
  • Thread-safe: I/O calls are serialized with a threading.Event lock.
  • Optional logging.Logger injection.
  • Backed by smbus2, so it works on any SBC with I2C support.

Requirements

  • Python 3.6+ (uses type hints).
  • An SBC with an I2C bus enabled.
  • smbus2.

Installation

pip install smbus2

Then drop cat9555.py next to your code and import the class:

from cat9555 import CAT9555

Usage

from 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()

API

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 lock

write_* methods return True on success and False if the I2C transaction raises. read_* methods return the 16-bit register value as an int.

License

MIT © 2022–2026 mdps


Un proyecto de mdps · 2026 · desarrollado en Murcia.

About

Python class for the CAT9555/TCA9555 16-bit I2C GPIO expander.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages