Simple node.js server for running on a computer (I used a Raspberry Pi) connected to a Fadecandy board. The server has a config file which allows for strips to be either single-color (these are RGB and transistor based - I use a SMD 5050 strip) or multi-colored (these are data based - I use Neopixel LED strips that have 30 LEDs per strip). The single-color strips are controlled using Pi Blaster, while the multi-color strips are controlled with the Fadecandy board, through the websocket set up by Fadecandy's fcserver
.
This application relies on the fact that a Fadecandy server is currently running on the host computer.
Data-based strips are easy to install. Instructions can be found on the GitHub page for Fadecandy. These strips allow for any LED to be individually controlled, and most of the patterns are written for these.
RGB-based single-colored strips are a bit more difficult to install, but are much cheaper. Most types of LEDs will work, but I have only tested these with 5050 types. A separate circuit board will need to be used, as the Pi cannot produce a PWM signal fast enough to drive LEDs. Instructions can be followed here. At this time, only one single-colored strip can be used - every strip connected will be the same color.
There is a file located at js/config.json
. There are a few options you can set which are loaded as soon as the app is run.
maxLedsPerStrip
: this is the number of LEDs per strip, imposed by the Fadecandy software. This part allows for multiple multi-colored strips to be used. Fadecandy takes in an address for each LED to be used, so to take advantage of this, the first LED on each strip plugged in to the Fadecandy board has an offset of (index * maxLedsPerStrip). This is cut off by ledsPerStrip
.
ledsPerStrip
: The actual number of LEDs per data strip. Fade-server will only write to this number of LEDs on each strip, but it can be more than you have if you have differently sized strips.
numStrips
: The number of multi-colored strips in different ports on the fadecandy board (starting at the 0 position on th board).
numOneColorStrips
: Right now should just be 0 or 1, depending on if you have a single-color strip attached to your Pi.
https
: Use HTTPS for the web server? This requires a valid certificate.
port
: Port to use for the web server. Should be 80. If HTTPS is true, the port will automatically be set to 443.
stripNames
: Array of strings which correspond to the strip names. Strips are displayed first by multi-colored, then single-colored.
I created a few patterns in the file js/patterns.js
. This file contains everything needed for patterns to be used on both the client-side (it includes CSS and animations for drawing the pattern styles on the webpage), as well as the server. This file also has the configuration settings for each pattern, as well as how the configuration is displayed and updates (for instance, dragging a value slider should update the value displayed).
Most of the patterns are written for the multi-colored strips, and these will not show up on the single-colored strip color picker.
Run the command 'npm install' from inside the fade-server folder. It is recommended that your config file be changed to suit your needs, such as the name of your strips (in order).
Run the command 'node app.js' from inside the fade-server folder - this command may have to be run as root. You can also add a port number at the end of the command. This will overwrite the port provided in config.js
You can get the app to run automatically if the following instruction set is followed.
The following must be added to /etc/rc.local
(or wherever startup scripts are stored on your device) to get fade-server (as well as fcserver - required if using the Fadecandy board and a multi-colored strip) to run on boot. Make sure to copy fcserver
from Fadecandy's repo to a root position such as /usr/local/bin/
so it can be run as root without the system needing to access the user folder, which may be protected.
/usr/local/bin/fcserver /usr/local/bin/fcserver.json >/var/log/fcserver.log 2>&1 &
node /home/pi/fade-server/app.js > /var/log/fade-server.log &