LED Data

The BPIOLED class provides support for controlling RGB LEDs, including WS2812/NeoPixel, APA102/DotStar, and the Bus Pirate’s onboard RGB LED.

Configuration

MethodParametersDescription
configure(led_type, **kwargs)led_type (str or int)
**kwargs (additional config)
Configure LED mode with specified LED type: ‘WS2812’, ‘APA102’, or ‘ONBOARD’ (or 0, 1, 2)

LED Operations

MethodParametersDescription
write(data)data (bytes or list)Write raw data to LED device
set_rgb(r, g, b, brightness)r (int, 0-255)
g (int, 0-255)
b (int, 0-255)
brightness (int, 0-31, default=31)
Set single LED to RGB color (brightness only for APA102)
set_rgbw(r, g, b, w, brightness)r (int, 0-255)
g (int, 0-255)
b (int, 0-255)
w (int, 0-255)
brightness (int, 0-31, default=31)
Set single RGBW LED (WS2812 only)
set_multiple_rgb(colors, brightness)colors (list of (r,g,b) tuples)
brightness (int, 0-31, default=31)
Set multiple LEDs with RGB values (brightness only for APA102)
clear(num_leds)num_leds (int, default=1)Turn off LEDs (set to black/off)

Basic Configuration - Onboard LED

>>> from bpio_client import BPIOClient
>>> from bpio_led import BPIOLED
>>> client = BPIOClient("COM35")
>>> led = BPIOLED(client)
>>> led.configure(led_type='ONBOARD')
True

Basic Configuration - WS2812 External LEDs

>>> led = BPIOLED(client)
>>> led.configure(led_type='WS2812', psu_enable=True, psu_set_mv=5000, psu_set_ma=0)
True

Basic Configuration - APA102 External LEDs

>>> led = BPIOLED(client)
>>> led.configure(led_type='APA102', psu_enable=True, psu_set_mv=5000, psu_set_ma=0)
True

Single LED Control

>>> # Set onboard LED to red
>>> led.configure(led_type='ONBOARD')
>>> led.set_rgb(255, 0, 0)

>>> # Set first WS2812 LED to green
>>> led.configure(led_type='WS2812', psu_enable=True, psu_set_mv=5000)
>>> led.set_rgb(0, 255, 0)

>>> # Set first APA102 LED to blue at 50% brightness
>>> led.configure(led_type='APA102', psu_enable=True, psu_set_mv=5000)
>>> led.set_rgb(0, 0, 255, brightness=15)

Multiple LED Control

>>> # Rainbow pattern on 5 WS2812 LEDs
>>> led.configure(led_type='WS2812', psu_enable=True, psu_set_mv=5000)
>>> rainbow = [
...     (255, 0, 0),    # Red
...     (255, 165, 0),  # Orange
...     (255, 255, 0),  # Yellow
...     (0, 255, 0),    # Green
...     (0, 0, 255),    # Blue
... ]
>>> led.set_multiple_rgb(rainbow)

>>> # Same pattern on APA102 with brightness control
>>> led.configure(led_type='APA102', psu_enable=True, psu_set_mv=5000)
>>> led.set_multiple_rgb(rainbow, brightness=20)

RGBW LEDs (WS2812 only)

>>> led.configure(led_type='WS2812', psu_enable=True, psu_set_mv=5000)
>>> # Set RGBW LED with white channel
>>> led.set_rgbw(255, 0, 0, 128)  # Red + half white

Clearing LEDs

>>> # Turn off first LED
>>> led.clear(num_leds=1)

>>> # Turn off first 10 LEDs in a strip
>>> led.clear(num_leds=10)

Brightness Control (APA102)

>>> led.configure(led_type='APA102', psu_enable=True, psu_set_mv=5000)
>>> # Test different brightness levels (0-31)
>>> for brightness in [31, 15, 7, 3, 1]:
...     led.set_rgb(255, 0, 0, brightness=brightness)
...     time.sleep(0.5)