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 spidev
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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rpi5_ws2812-0.1.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rpi5_ws2812-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / rpi5_ws2812-0.1.2.tar.gz
| Download URL | rpi5_ws2812-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5eb0f7f709429f336be2617946bad7a45ddaafafd36e817a2c2df15f08e61e0
|
|
BLAKE2b-256 checksum How to use checksums |
834bfcd174ff64505b01f2d330408504c52380d32f16ee48e1b38a754159f0b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / rpi5_ws2812-0.1.2-py3-none-any.whl
| Download URL | rpi5_ws2812-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f70a8618bdf5c7dc4adddb3d16f0c4cd8bef3e1fb6678205140e5a46f5e009f
|
|
BLAKE2b-256 checksum How to use checksums |
6280183e7021b4f06fcdae659021fc5934b011fc3b47a3b98bf219979cbce6a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|