A very basic app to control WS2812 LED strips with a raspberry pi.
This consists of a Node app which serves a simple HTML page to manage the strip and includes libraries to control the strip.
You can use it for WS2812 (NeoPixel) christmas lights, or other simple DIY applications. I used it for a couple applications, including Christmas Tree Lights and an artistic decorative dodecahedron.
Its also possible to integrate your LED-Strip to Homebridge. With that you can control the Strip via Apple Home App
- Static Color
- Set A Static Color and adjust the brightness
- Rainbow
- Cycle through all colors and pulse through strip.
- Fade 2 Colors
- Choose 2 colors and fade the strip between them.
- Dance
- Each LED is rapidly moving through the color wheel, giving a 'disco' / 'dance' effect.
- Starry Night
- Twinkling, white LED effects to simulate stars! ⭐
- Christmas Tree
- Randomly cycle R / G / B / W through the strip.
- Christmas Iterate
- Iterate a segment of R / G / B / W LEDs through the strip from top to bottom and bottom to top
I found this NPM package : https://www.npmjs.com/package/rpi-ws281x-native Read this page.
It led me to follow the instructions here at Adafruit: https://learn.adafruit.com/neopixels-on-raspberry-pi.
I used a WS2812 and just connected it to a Raspberry Pi Zero W GPIO 18 and it worked.
- WS2812 (Neopixel) LED Light Strip or LEDs
- Raspberry Pi 3 Model B, Raspberry Pi Zero, or Raspberry Pi Model B (other Raspberry Pis should work fine but are untested)
- 5V Power Supply
- At 5V , each LED from WS2812b draws about 50mA when set to its full brightness. For 30 LEDs its 1.5A
- I also powered my Raspberry Pi over the 5V Power Supply and it works fine.
- Connect DATA IN of your WS2812 LED strip to physical pin 12 of the Raspberry Pi. (GPIO 18).
- Connect GND (Physical pin 6) to the GND lead of your power supply.
- Refer to this image for a layout of the raspi pins: https://www.element14.com/community/servlet/JiveServlet/previewBody/73950-102-11-339300/pi3_gpio.png
Optional if you want to power your Rapsberry Pi also via the Powersupply: 3. Connect a Cable from the Power Supply V+ to the physical pin 2 of the Raspberry Pi. 3. Connect a Cable from the Power Supply V- to a ground pin of the Raspberry Pi.
Tested working on:
- Raspberry Pi 3 Model B
- Raspberry Pi Zero W (some slowness can occur)
- Raspberry Pi Model B (some slowness can occur)
- Install NodeJS
- Copy this repo to some location on your pi
- Easy option: use git
sudo apt install git
git clone https://github.com/luxdvie/WS2812Controller.git
- Easy option: use git
- During node setup, I ran into some permissions issues with the
rpi-ws281x-native
package on my pi zero. I performed these steps:- add following lines to
~/.bashrc
after installing npm:then run:npm set prefix ~/.npm PATH="$HOME/.npm/bin:$PATH" PATH="./node_modules/.bin:$PATH" Execute following line after changes:
source ~/.bashrc
- add following lines to
- Globally install the node-gyp package
npm i -g node-gyp
- Run
npm install
in the root of this project to install all dependencies- Important troubleshooting note If you run into issues during installation, you may want to try deleting the
package-lock.json
andnode_modules
directory, and tryingnpm install
again. Avoid usingsudo
for npm install if you can!
- Important troubleshooting note If you run into issues during installation, you may want to try deleting the
- Modify NUM_LEDS in
strip.js
to match the number of LEDs you have connectedvar NUM_LEDS = <YOUR_LEDS_HERE>;
- Modify HTTP_PORT in app.js to match the port you want to use to access your Pi.
var HTTP_PORT = <YOUR_PORT_HERE>;
- Run app.js as root user or with sudo privileges.
node /path/to/me/app.js
- Access app.html to control the LED strip from the IP Address of your raspi.
http://<YOUR_IP_ADDRESS_HERE>:<YOUR_PORT_HERE>/
Create a new File /etc/systemd/system/<service>.service
replace with your own service’s name) with the following content.
[Unit]
Description=WS2812b Controller with Homebride functionality
After=network.target
[Service]
User=root
WorkingDirectory=<path to your app>
ExecStart=<app start command f.g. node app.js>
Restart=always
[Install]
WantedBy=multi-user.target
Then, reload systemd, enable the service and finally, start it.
$ sudo systemctl daemon-reload
$ sudo systemctl enable <service>
$ sudo systemctl start <service>
It is possible to control the Strip with the Apple Home App over Homebridge. At first go to your Homebridge and install homebridge-better-http-rgb
After installing this go to the Plugin Settings an configure your Strip.
Example:
{
"accessory": "HTTP-RGB",
"name": "LED Strip",
"service": "Light",
"switch": {
"status": "http://<your_raspberrypi_ip>:8080/api/v1/status",
"powerOn": "http://<your_raspberrypi_ip>:8080/api/v1/on",
"powerOff": "http://<your_raspberrypi_ip>:8080/api/v1/off"
},
"color": {
"status": "http://<your_raspberrypi_ip>:8080/api/v1/color",
"url": "http://<your_raspberrypi_ip>:8080/api/v1/color/%s"
},
"brightness": {
"status": "http://<your_raspberrypi_ip>:8080/api/v1/brightness",
"url": "http://<your_raspberrypi_ip>:8080/api/v1/brightness/%s"
}
}
Disclaimer The rpi-ws281x-native
package requires root access, so you have to run the app.js
with sudo
or as root
... Do this at your own risk :) I never expose my Pi to the internet, so I'm not as concerned about this, but definitely I would not recommend you ever expose this service to the internet, especially when configured this way!
Original Author: Austin Brown GitHub, austinbrown2500@gmail.com
Author for AddOns (Homebridge, etc): Dominic Rösch GitHub, 256domi@googlemail.com
Although already forbidden by the sources and subsequent licensing, it is not allowed to use or distribute this software for a commercial purpose.
HomeKit Accessory Protocol (HAP) is Apple’s proprietary protocol that enables third-party accessories in the home (e.g., lights, thermostats and door locks) and Apple products to communicate with each other. HAP supports two transports, IP and Bluetooth LE. The information provided in the HomeKit Accessory Protocol Specification (Non-Commercial Version) describes how to implement HAP in an accessory that you create for non-commercial use and that will not be distributed or sold. The HomeKit Accessory Protocol Specification (Non-Commercial Version) can be downloaded from the HomeKit Apple Developer page. Copyright © 2020 Apple Inc. All rights reserved.