Skip to main content

A library to control WS2812 LEDs with a Raspberry Pi 5

Project description

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 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpi5_ws2812-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

rpi5_ws2812-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file rpi5_ws2812-0.1.0.tar.gz.

File metadata

  • Download URL: rpi5_ws2812-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for rpi5_ws2812-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4dc0b8d13258c7bee0ad264899fc020c3ecc3d8929f5422ec3dc0f3407cdb342
MD5 110d49c66fb93d28e1141373b96190b6
BLAKE2b-256 3b39ab638f68e92e65397ce569ed7329ebc822bda6aacac4fea50927c288b846

See more details on using hashes here.

File details

Details for the file rpi5_ws2812-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rpi5_ws2812-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for rpi5_ws2812-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9402f5aa0d2600bb3f0009932a9aee3ac9a40b9cf8fd23737730437e80a475f3
MD5 27c229839a4b82bde1e804e0c0f5a8e4
BLAKE2b-256 c091288fddd9cf97eae36bd8005f3bae06d14c4ca2128cab4a370a71d15a2b17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page