Skip to main content

A library to control WS2812 LEDs using SPI on Orange Pi

Project description

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.

## 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 ws2812-gpt-lp

Usage example

from ws2812_gpt_lp import WS2812

Configuration

num_leds = 8 -> Numbers of LED you are using
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)
]

Send colors to LEDs

ws2812.send_colors(colors)

Change the color of the first LED to blue

ws2812.send_color(0, 0, 0, 255)

Turn off all LEDs

ws2812.send_off()

Set all LEDs to red

ws2812.send_to_all(255, 0, 0)

Close the SPI connection

ws2812.close()

Example.py

import spidev
from ws2812_gpt_lp import WS2812
import time

if __name__ == "__main__":
    num_leds = 8
    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.

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

ws2812_gpt_lp-0.1.4.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ws2812_gpt_lp-0.1.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file ws2812_gpt_lp-0.1.4.tar.gz.

File metadata

  • Download URL: ws2812_gpt_lp-0.1.4.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for ws2812_gpt_lp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ba3d71e5d402ebf9c378370613e50d17867833c92cbe04e012e56dc6a5e3e9a7
MD5 2fd12a9f7fa2868e23bc0b3102ea7abd
BLAKE2b-256 1732291650099a3a64a6f8fe22bc8c49e9da18e022622ee252d4e884789f56c4

See more details on using hashes here.

File details

Details for the file ws2812_gpt_lp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ws2812_gpt_lp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for ws2812_gpt_lp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4dbb1710b0928d0fa518fa3e9217ba175129d403e99bf8c78c909aaef0989b8b
MD5 49a203847de25d080280cf7e2b0bc900
BLAKE2b-256 f6d0132252a83f25f2130d3516eb30f7b3b277389ddda7af3c894dfd88498465

See more details on using hashes here.

Supported by

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