Simple test
Ensure your device works with this simple test.
examples/pca9955b_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2025 Noel Anderson
2#
3# SPDX-License-Identifier: Unlicense
4
5import time
6
7import board
8import busio
9
10from pca9955b import PCA9955, LedChannel
11
12# Create I2C bus.
13i2c = busio.I2C(board.SCL, board.SDA)
14
15
16ledDriver = PCA9955(i2c, address=0x3F, oe_pin=board.GP10, reset_pin=board.GP11)
17ledDriver.reset()
18ledDriver.output_enable = True
19
20
21ledDriver.gain = 0xFF
22ledDriver.brightness = 0x7F # 50% brightness
23
24# Manually turn on, then off the first channel
25ledDriver.channels[0].state = LedChannel.ON
26time.sleep(5)
27
28ledDriver.channels[0].state = LedChannel.OFF
29time.sleep(5)
30
31# Gradualy increase brightness from off to fully bright for channel 12
32ledDriver.channels[12].state = LedChannel.PWM
33for i in range(255):
34 ledDriver.channels[12].brightness = i
35 time.sleep(0.02)
Global Control (Blinking)
This example uses global controls to continuously blink lights without having the processor to do anything.
examples/pca9955b_global_control.py
1# SPDX-FileCopyrightText: Copyright (c) 2025 Noel Anderson
2#
3# SPDX-License-Identifier: Unlicense
4
5
6# This sample uses the global features to continious blink channels 0 and 3.
7# Once started this blinking pattern will run without additional program input, until stopped
8
9import time
10
11import board
12import busio
13
14from pca9955b import PCA9955, LedChannel
15
16# Create I2C bus.
17i2c = busio.I2C(board.SCL, board.SDA)
18
19
20ledDriver = PCA9955(i2c, address=0x3F, oe_pin=board.GP10, reset_pin=board.GP11)
21ledDriver.reset()
22ledDriver.output_enable = True
23
24
25# Global settings
26ledDriver.brightness = 0x7F # 50% brightness
27ledDriver.gain = 0xFF # Max
28
29# Use channels 0 & 3
30ledDriver.channels[0].state = LedChannel.PWM_GRP
31ledDriver.channels[3].state = LedChannel.PWM_GRP
32
33# Blink leds approx once per second with a 50% duty cycle
34ledDriver.pwm = 0x7F # 50% duty cycle (pwm/256) as per data sheet 7.3.4
35ledDriver.frequency = 15 # ~1 sec (frequency+1/15.6) as per data sheet 7.3.5
36
37# Start
38ledDriver.blinking = True
39
40time.sleep(30)
41
42# Stop
43ledDriver.blinking = False
44ledDriver.channels[0].state = LedChannel.OFF
Group Control (Sawtooth pattern)
This example uses group controls to have a set of channels continuously turn on, brighten, and then turn off in a sawtoth patttern, without processor activity.
examples/pca9955b_group_control.py
1# SPDX-FileCopyrightText: Copyright (c) 2025 Noel Anderson
2#
3# SPDX-License-Identifier: Unlicense
4
5
6# This sample uses the group feature to run channels 0 and 13 in a continious sawwave pattern.
7# Once started the group will run without any additional input, until stopped
8
9import time
10
11import board
12import busio
13
14from pca9955b import PCA9955, LedChannel
15
16# Create I2C bus.
17i2c = busio.I2C(board.SCL, board.SDA)
18
19
20ledDriver = PCA9955(i2c, address=0x3F, oe_pin=board.GP10, reset_pin=board.GP11)
21ledDriver.reset()
22ledDriver.output_enable = True
23
24
25# Global settings
26ledDriver.brightness = 0x7F # 50% brightness
27ledDriver.gain = 0xFF # Max
28
29# Configure the channels for graduation & assign to group 0
30ledDriver.channels[0].output_state = LedChannel.PWM_GRP
31ledDriver.channels[0].groupId = 0
32ledDriver.channels[0].graduation_mode = True
33
34ledDriver.channels[13].output_state = LedChannel.PWM_GRP
35ledDriver.channels[13].groupId = 0
36ledDriver.channels[13].graduation_mode = True
37
38# Configure the group.
39# Creates a group with two channels automatically following this sawtooth pattern -
40# * gradually ramp on
41# * hold on for 0.5 second
42# * turn off
43# * hold off for 0.5 seconds
44# Repeats till stopped
45# _ _ _ _ _ _ _
46# / |_/ |_/ |_/ |_/ |_/ |_/ |
47#
48ledDriver.groups[0].factor_per_step = 32
49ledDriver.groups[0].cycle_time = 1 # 0.5ms
50
51ledDriver.groups[0].ramp_rate = 10
52ledDriver.groups[0].ramp_up = True
53ledDriver.groups[0].ramp_down = False
54
55ledDriver.groups[0].hold_off = True
56ledDriver.groups[0].hold_off_time = 1 # 0.5s
57
58ledDriver.groups[0].hold_on = True
59ledDriver.groups[0].hold_on_time = 1 # 0.5s
60
61ledDriver.groups[0].gain = 0x7F
62
63
64# Start the group running. This will run the pattern continuously without
65# any CPU intervention until manually stopped
66ledDriver.groups[0].graduation_mode = 1 # Continuous
67ledDriver.groups[0].graduation_start()
68
69time.sleep(30)
70
71# Stop the group
72ledDriver.groups[0].graduation_stop()