Skip to main content

WS2812 interface for the Raspberry Pi 5

This is a simple interface for the WS2812 LED strip for the Raspberry Pi 5. Currently it only supports communication over the SPI interface.

This library was created for the Raspberry Pi 5 because the previous go-to library rpi_ws281x is not (yet?) compatible. It should work on other Raspberry Pi models as well, but this has not been tested.

Thanks to this repository for the research on the SPI communication.

Preparation

Enable SPI on the Raspberry Pi 5:

sudo raspi-config

Navigate to Interfacing Options -> SPI and enable it.

Optional: add your user to the spi group to avoid running the script as root:

sudo adduser YOUR_USER spi

Installation

pip install rpi5-ws2812

Wiring

Connect the DIN (Data In) pin of the WS2812 strip to the MOSI (Master Out Slave In) pin of the Raspberry Pi 5. The MOSI pin is pin 19 / GPIO10 on the Raspberry Pi 5.

Usage

from rpi5_ws2812.ws2812 import Color, WS2812SpiDriver
import time

if __name__ == "__main__":

    # Initialize the WS2812 strip with 100 leds and SPI channel 0, CE0
    strip = WS2812SpiDriver(spi_bus=0, spi_device=0, led_count=100).get_strip()
    while True:
        strip.set_all_pixels(Color(255, 0, 0))
        strip.show()
        time.sleep(2)
        strip.set_all_pixels(Color(0, 255, 0))
        strip.show()
        time.sleep(2)

Use this library in a docker container

To use this library in a docker container, you need to add the --device flag to the docker run command to give the container access to the SPI interface. You also need to run the container in privileged mode.

Example:

docker run --device /dev/spidev0.0 --privileged YOUR_IMAGE
services:
  your_service:
    image: YOUR_IMAGE
    privileged: true
    devices:
      - /dev/spidev0.0

Metadata

Release files for rpi5-ws2812 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rpi5-ws2812 0.1.3
File Size Uploaded Provenance Actions
rpi5_ws2812-0.1.3.tar.gz 5.4 kB Without provenance Details for rpi5_ws2812-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rpi5-ws2812 0.1.3
File Interpreter ABI Platform Actions
rpi5_ws2812-0.1.3-py3-none-any.whl Python 3 none any Details for rpi5_ws2812-0.1.3-py3-none-any.whl

Total release size: 10.2 kB

Release files / rpi5_ws2812-0.1.3.tar.gz

Download URL rpi5_ws2812-0.1.3.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7cbc2751c3359d2e9f5bbe0b0c99466f8fc23fd8e7b2630e3ba32eabe569e69f
BLAKE2b-256 checksum
How to use checksums
b215ac3bd597d8e3906789ccd25c7ce0aa8e7a19a23b724dd11febd997a3d5ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / rpi5_ws2812-0.1.3-py3-none-any.whl

Download URL rpi5_ws2812-0.1.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b7e244fd58ba2cd86d800af70791bdf59ea0e4f8cf2b353ffac12075b7c06b6
BLAKE2b-256 checksum
How to use checksums
14bd495e9c0b301a1a6e94ee9710bebf234687b0ba1aed03e0227dc48a942489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for rpi5-ws2812 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page