Python library for the TLC59108 and TLC59116 constant-current LED sink driver
Project description
tlc591xx-python
Python library for the TLC59108 (8-channel) and TLC59116 (16-channel) constant-current LED sink drivers over I²C.
Features
- Unified
TLC591xxbase class with chip-specificTLC59108andTLC59116subclasses - Per-channel brightness control (
0= off,1–254= PWM,255= full on) - Bulk update of all channels in a single I²C block write (
set_all_brightness) - Context-manager support — bus is automatically closed on exit
- Error-flag register reading (
read_errors) for open-load / over-temperature diagnostics - Works with any
smbus2-compatible bus object or a plain integer bus number
Installation
pip install tlc591xx
Requires Python ≥ 3.12 and smbus2.
On a Raspberry Pi, make sure I²C is enabled:
sudo raspi-config # Interface Options → I2C → Enable
Quick Start
TLC59108 (8 channels, default address 0x40)
from tlc591xx import TLC59108
with TLC59108(bus=1) as drv:
drv.set_brightness(0, 255) # channel 0 fully on
drv.set_brightness(1, 128) # channel 1 at ~50 % PWM
drv.set_all_brightness([255] * 8) # all channels on
drv.set_all_off() # all channels off
TLC59116 (16 channels, default address 0x60)
from tlc591xx import TLC59116
with TLC59116(bus=1) as drv:
drv.set_all_brightness(list(range(0, 256, 16))) # brightness gradient
Sharing an existing SMBus instance
from smbus2 import SMBus
from tlc591xx import TLC59108
with SMBus(1) as bus:
drv = TLC59108(bus, address=0x41) # external bus: not closed by driver
drv.set_brightness(3, 200)
API Reference
TLC59108(bus, address=0x40)
TLC59116(bus, address=0x60)
| Parameter | Type | Description |
|---|---|---|
bus |
int or SMBus |
I²C bus number (/dev/i2c-<n>) or an open SMBus instance |
address |
int |
7-bit I²C address — must match the A0–A3 pin strapping on the board |
Methods
| Method | Description |
|---|---|
set_brightness(channel, value) |
Set one channel. value: 0 = off, 1–254 = PWM, 255 = full on |
set_all_brightness(values) |
Set all channels from a list; length must equal num_leds. Uses a single I²C block write |
set_all_off() |
Force all outputs off |
read_errors() |
Return (eflag1, eflag2) error-flag bytes; TLC59108 always returns eflag2 = 0 |
read_register(reg) |
Read any 8-bit register by address (useful for diagnostics) |
close() |
Release the bus if it was opened by the driver |
Properties
| Property | Description |
|---|---|
address |
The I²C address the driver was configured with |
num_leds |
Number of output channels (8 for TLC59108, 16 for TLC59116) |
I²C Address Selection
Both chips use four address pins (A0–A3) to set the 7-bit I²C address. The base addresses are:
| Chip | Base address | Range |
|---|---|---|
| TLC59108 | 0x40 |
0x40–0x4F |
| TLC59116 | 0x60 |
0x60–0x6F |
Pass the matching address as the address parameter. Example with non-default strapping:
drv = TLC59108(bus=1, address=0x43) # A0=1, A1=1, A2=0, A3=0
Examples
Blink all outputs
# From the repo root (no install required):
PYTHONPATH=src python3 examples/tlc59108_blink.py
PYTHONPATH=src python3 examples/tlc59108_blink.py --bus 1 --delay 0.2
Multi-channel fade / wave
PYTHONPATH=src python3 examples/tlc59108_fade.py -v
PYTHONPATH=src python3 examples/tlc59108_fade.py -c 0,1,5,6 --delay 0.05
Development
git clone https://github.com/trackIT-Systems/tlc591xx-python.git
cd tlc591xx-python
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
Run unit tests (no hardware required)
pytest -m "not hardware"
Run hardware tests
Connect a TLC591xx chip on I²C and set the environment variables:
TLC591XX_I2C_BUS=1 TLC591XX_MODEL=TLC59108 pytest -m hardware -v
| Variable | Default | Description |
|---|---|---|
TLC591XX_I2C_BUS |
— | I²C bus number (required for hardware tests) |
TLC591XX_ADDRESS |
chip default | Override the I²C address |
TLC591XX_MODEL |
TLC59108 |
TLC59108 or TLC59116 |
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tlc591xx-0.1.0.tar.gz.
File metadata
- Download URL: tlc591xx-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ac6f5e0076caddc4eb40d5f26d5bcd43d5e6e9968f638ac941fffb443c8ae99
|
|
| MD5 |
0320148111febf67191f8c789e2a8d15
|
|
| BLAKE2b-256 |
298f57b659d28300d0c3fdd1c8d70b6efb4a45d657456fb1bf31ec05a15fc927
|
Provenance
The following attestation bundles were made for tlc591xx-0.1.0.tar.gz:
Publisher:
publish.yml on trackIT-Systems/tlc591xx-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlc591xx-0.1.0.tar.gz -
Subject digest:
7ac6f5e0076caddc4eb40d5f26d5bcd43d5e6e9968f638ac941fffb443c8ae99 - Sigstore transparency entry: 1461999822
- Sigstore integration time:
-
Permalink:
trackIT-Systems/tlc591xx-python@499154d666e0ec722abf2cf8e974d71155a578b2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trackIT-Systems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@499154d666e0ec722abf2cf8e974d71155a578b2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tlc591xx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tlc591xx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0061cee810040d47bd84f4e48165b597e73c08a1151c847411e8e4ca70c2709
|
|
| MD5 |
6ecc05474ae8feb996f5a2f88819d5f5
|
|
| BLAKE2b-256 |
3e02aa6a5fbd6d7ffe0b242477235eee165f53862c4d36fee1569f334ed9e814
|
Provenance
The following attestation bundles were made for tlc591xx-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on trackIT-Systems/tlc591xx-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlc591xx-0.1.0-py3-none-any.whl -
Subject digest:
b0061cee810040d47bd84f4e48165b597e73c08a1151c847411e8e4ca70c2709 - Sigstore transparency entry: 1461999861
- Sigstore integration time:
-
Permalink:
trackIT-Systems/tlc591xx-python@499154d666e0ec722abf2cf8e974d71155a578b2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trackIT-Systems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@499154d666e0ec722abf2cf8e974d71155a578b2 -
Trigger Event:
push
-
Statement type: