vanshksingh / Pi5Neo

Library to Control Neopixel on Raspberry Pi 5 using python
MIT License
10 stars 5 forks source link

Pi5Neo

Simplifying NeoPixel LED Control on Raspberry Pi 5 via SPI (GPIO 10)

PyPI version Python Versions License

IMG_7596

Pi5Neo is a Python library designed to make controlling NeoPixel LED strips super easy and efficient on the Raspberry Pi 5 (or equivalent boards). Whether you're creating dazzling light shows, informative displays, or ambient lighting, Pi5Neo simplifies the process using the Raspberry Pi’s SPI interface for high-performance communication.

🌟 Key Features

πŸš€ Installation

You can install Pi5Neo via pip:

pip install pi5neo

Requirements

Hardware

πŸ“š Usage

Pi5Neo makes it straightforward to set up and control your NeoPixel strip. Here's a simple example:

from pi5neo import Pi5Neo

# Initialize the Pi5Neo class with 10 LEDs and an SPI speed of 800kHz
neo = Pi5Neo('/dev/spidev0.0', 10, 800)

# Fill the strip with a red color
neo.fill_strip(255, 0, 0)
neo.update_strip()  # Commit changes to the LEDs

# Set the 5th LED to blue
neo.set_led_color(4, 0, 0, 255)
neo.update_strip()

🌈 Examples

You can find more advanced examples in the examples directory. Here’s a quick showcase of some cool effects you can create with Pi5Neo:

Example 1: Rainbow Cycle

from pi5neo import Pi5Neo
import time

def rainbow_cycle(neo, delay=0.1):
    colors = [
        (255, 0, 0),  # Red
        (255, 127, 0),  # Orange
        (255, 255, 0),  # Yellow
        (0, 255, 0),  # Green
        (0, 0, 255),  # Blue
        (75, 0, 130),  # Indigo
        (148, 0, 211)  # Violet
    ]
    for color in colors:
        neo.fill_strip(*color)
        neo.update_strip()
        time.sleep(delay)

neo = Pi5Neo('/dev/spidev0.0', 10, 800)
rainbow_cycle(neo)

Example 2: Loading Bar Effect

from pi5neo import Pi5Neo
import time

def loading_bar(neo):
    for i in range(neo.num_leds):
        neo.set_led_color(i, 0, 255, 0)  # Green loading bar
        neo.update_strip()
        time.sleep(0.2)
    neo.clear_strip()
    neo.update_strip()

neo = Pi5Neo('/dev/spidev0.0', 10, 800)
loading_bar(neo)

βš™οΈ Configuration

You can configure Pi5Neo by passing in different parameters for the number of LEDs, SPI speed, and more:

Pi5Neo('/dev/spidev0.0', num_leds=20, spi_speed_khz=1000)

πŸ› οΈ Contributing

We welcome contributions from the community! To contribute:

  1. Fork the repo.
  2. Create a new branch (git checkout -b my-feature).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin my-feature).
  5. Create a new Pull Request.

Feel free to open issues for bugs, questions, or feature requests.

πŸ“ License

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

❀️ Acknowledgements

Pi5Neo was inspired by various open-source projects that aim to make hardware control easier and more accessible. Special thanks to the contributors of spidev and Raspberry Pi for their amazing support!


Now, let your Raspberry Pi 5 light up the room with Pi5Neo!


πŸ”— Useful Links