rpi5-ws2812


Namerpi5-ws2812 JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/niklasr22/rpi5-ws2812
SummaryA library to control WS2812 LEDs with a Raspberry Pi 5
upload_time2024-08-18 10:53:20
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT
keywords raspberry pi rpi ws2812 led spi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/jgarff/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](https://github.com/mattaw/ws2812_spi_python/) for the research on the SPI communication.

## Preparation

Enable SPI on the Raspberry Pi 5:

```bash
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:

```bash
sudo adduser YOUR_USER spidev
```

## Installation

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

```python
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:

```bash
docker run --device /dev/spidev0.0 --privileged YOUR_IMAGE
```

```yaml
services:
  your_service:
    image: YOUR_IMAGE
    privileged: true
    devices:
      - /dev/spidev0.0
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/niklasr22/rpi5-ws2812",
    "name": "rpi5-ws2812",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "raspberry, pi, rpi, ws2812, led, spi",
    "author": null,
    "author_email": "byrousset@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/83/4b/fcd174ff64505b01f2d330408504c52380d32f16ee48e1b38a754159f0b3/rpi5_ws2812-0.1.2.tar.gz",
    "platform": null,
    "description": "# WS2812 interface for the Raspberry Pi 5\n\nThis is a simple interface for the WS2812 LED strip for the Raspberry Pi 5.\nCurrently it only supports communication over the SPI interface.\n\nThis library was created for the Raspberry Pi 5 because the previous go-to library [rpi_ws281x](https://github.com/jgarff/rpi_ws281x) is not (yet?) compatible. It should work on other Raspberry Pi models as well, but this has not been tested.\n\nThanks to [this repository](https://github.com/mattaw/ws2812_spi_python/) for the research on the SPI communication.\n\n## Preparation\n\nEnable SPI on the Raspberry Pi 5:\n\n```bash\nsudo raspi-config\n```\n\nNavigate to `Interfacing Options` -> `SPI` and enable it.\n\nOptional: add your user to the `spi` group to avoid running the script as root:\n\n```bash\nsudo adduser YOUR_USER spidev\n```\n\n## Installation\n\n```bash\npip install rpi5-ws2812\n```\n\n## Wiring\n\nConnect 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.\n\n## Usage\n\n```python\nfrom rpi5_ws2812.ws2812 import Color, WS2812SpiDriver\nimport time\n\nif __name__ == \"__main__\":\n\n    # Initialize the WS2812 strip with 100 leds and SPI channel 0, CE0\n    strip = WS2812SpiDriver(spi_bus=0, spi_device=0, led_count=100).get_strip()\n    while True:\n        strip.set_all_pixels(Color(255, 0, 0))\n        strip.show()\n        time.sleep(2)\n        strip.set_all_pixels(Color(0, 255, 0))\n        strip.show()\n        time.sleep(2)\n```\n\n## Use this library in a docker container\n\nTo 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.\n\nExample:\n\n```bash\ndocker run --device /dev/spidev0.0 --privileged YOUR_IMAGE\n```\n\n```yaml\nservices:\n  your_service:\n    image: YOUR_IMAGE\n    privileged: true\n    devices:\n      - /dev/spidev0.0\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library to control WS2812 LEDs with a Raspberry Pi 5",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/niklasr22/rpi5-ws2812/issues",
        "Homepage": "https://github.com/niklasr22/rpi5-ws2812"
    },
    "split_keywords": [
        "raspberry",
        " pi",
        " rpi",
        " ws2812",
        " led",
        " spi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6280183e7021b4f06fcdae659021fc5934b011fc3b47a3b98bf219979cbce6a1",
                "md5": "4ea7e15c2a075693e3a9e30a78f2726a",
                "sha256": "3f70a8618bdf5c7dc4adddb3d16f0c4cd8bef3e1fb6678205140e5a46f5e009f"
            },
            "downloads": -1,
            "filename": "rpi5_ws2812-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ea7e15c2a075693e3a9e30a78f2726a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 4828,
            "upload_time": "2024-08-18T10:53:19",
            "upload_time_iso_8601": "2024-08-18T10:53:19.168052Z",
            "url": "https://files.pythonhosted.org/packages/62/80/183e7021b4f06fcdae659021fc5934b011fc3b47a3b98bf219979cbce6a1/rpi5_ws2812-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "834bfcd174ff64505b01f2d330408504c52380d32f16ee48e1b38a754159f0b3",
                "md5": "287b248b2573672a08c2dfec236de05a",
                "sha256": "b5eb0f7f709429f336be2617946bad7a45ddaafafd36e817a2c2df15f08e61e0"
            },
            "downloads": -1,
            "filename": "rpi5_ws2812-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "287b248b2573672a08c2dfec236de05a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 4474,
            "upload_time": "2024-08-18T10:53:20",
            "upload_time_iso_8601": "2024-08-18T10:53:20.513902Z",
            "url": "https://files.pythonhosted.org/packages/83/4b/fcd174ff64505b01f2d330408504c52380d32f16ee48e1b38a754159f0b3/rpi5_ws2812-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 10:53:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "niklasr22",
    "github_project": "rpi5-ws2812",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "rpi5-ws2812"
}
        
Elapsed time: 0.98737s