Skip to main content

WS2812-GPT-LP

This library allows you to control WS2812 LEDs using SPI on Orange Pi. Tested on Orange Pi 5 plus.
Cette bibliothèque permet de contrôler les LEDs WS2812 via SPI sur Orange Pi. Testé avec succés sur Orange Pi 5 plus.

Important Note

You must solder a 100nF capacitor between the VCC and GND of the WS2812 LEDs to avoid interference.

Before you start

Depending on the board you are using, multiple SPI buses may be enabled depending on which pin you want to use.
For example, on the Orange Pi 5 Plus, there are 3 SPI buses: SPI0-m2, SPI4-m1, and SPI4-m2.
You must connect the signal line of the WS2812 LEDs to the MOSI pin of the SPI bus that you have activated on your Orange Pi.
You should refer to this table: http://www.orangepi.org/orangepiwiki/index.php/Orange_Pi_5_Plus#40_pin_SPI_test_2

If you enable SPI0-m2, the LED must be connected to pin 19.
If you enable SPI4-m1, the LED should be connected to pin 12.
If you enable SPI4-m2, the LED should be connected to pin 8.

Example of SPI4-m2 activation: you must edit the file /boot/armbianenv.txt or /boot/dietpiEnv.txt
and add this line: overlays=spi4-m2-cs0-spidev

The different activated modules must be separated by a space:
overlays=i2c2-m0 spi4-m2-cs0-spidev pwm11-m0

After saving your file, you must reboot.

After reboot, you can check the correct loading of the SPI module by running: ls /dev/spi*
It should return something like: /dev/spidev4.0

Notice the ending /dev/spidev4.0 => 4 and 0 you will need to config the library. First number is spi_bus, second number is spi_device, hold it.

Remember that all this concerns exclusively the Orange Pi 5 Plus board. If you use another board, you must refer to its documentation to know the SPI buses.

Installation

pip install spidev ws2812-gpt-lp

Usage example

from ws2812_gpt_lp import WS2812

Configuration

If numbers of LED you are using is 12:
num_leds = 12
ws2812 = WS2812(spi_bus=4, spi_device=0, num_leds=num_leds)

Example - Set colors for 8 LEDs

The color is defined by a value which goes from 0 to 255 the maximum.

colors = [
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(0, 255, 255), # Cyan
(255, 0, 255), # Magenta
(255, 255, 255), # White
(0, 0, 0) # Black (off)
]

ws2812.send_colors(colors)

Change the color of the first LED to blue

ws2812.send_color(0, 0, 0, 255) # Usage : send_color( LED_index, Red_ value, Green_value, Blue_value )

Turn off all LEDs

ws2812.send_off()

Set all LEDs to red

ws2812.send_to_all(255, 0, 0) # Usage : send_to_all( Red_value, Green_value, Blue_value )

Close the SPI connection

ws2812.close()

Example.py

  • Connect the plus of the ws2812 LED to the VCC 5V pin.
  • Connect the Sign IN pin of the LED to physical pin 8 of the Orange Pi.
  • Connect the GND pin of the LED to any GND pin di pi.
import spidev
from ws2812_gpt_lp import WS2812
import time

if __name__ == "__main__":
    num_leds = 12
    ws2812 = WS2812(spi_bus=4, spi_device=0, num_leds=num_leds)

    # Changer la couleur de la première LED à bleu
    ws2812.send_color(0, 0, 0, 255)
    time.sleep(5)

    # Éteindre toutes les LEDs
    ws2812.send_off()
    time.sleep(1)

    # Envoyer la couleur rouge à toutes les LEDs
    ws2812.send_to_all(255, 0, 0)
    time.sleep(5)

    # Éteindre toutes les LEDs
    ws2812.send_off()

    # Terminer la connexion SPI
    ws2812.close()

run with :

python3 Example.py

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

This library was jointly developed by Laurent Pastor and ChatGPT 4.

Metadata

Release files for ws2812-gpt-lp 0.1.8

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

Source distribution (sdist)

Source distribution for ws2812-gpt-lp 0.1.8
File Size Uploaded
ws2812_gpt_lp-0.1.8.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ws2812-gpt-lp 0.1.8
File Interpreter ABI Platform
ws2812_gpt_lp-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / ws2812_gpt_lp-0.1.8.tar.gz

Download URL ws2812_gpt_lp-0.1.8.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f830834060021c7f7d0f21747f76a01ad4c0bed70afa9331710db48681f61212
BLAKE2b-256 checksum
How to use checksums
2a3894efccded5eb070458d96053aa199a011353128e2ca6be5db31ec6be793b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.2

Release files / ws2812_gpt_lp-0.1.8-py3-none-any.whl

Download URL ws2812_gpt_lp-0.1.8-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3adcfcff0ee885fc7d4b78d4535f1442cada74ad809c345e6c003f578ba755d
BLAKE2b-256 checksum
How to use checksums
2174b75ba38777d18d02fc6937ed188677f1ddeda41c5145f1061f059d93dd60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

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