RPi Node-Red: Neopixel LED Ring
Use string injection nodes and a specific LED ring node to control a LED ring
What You Will Learn:
- Basic Node-Red Programming
What You Need to Know:
Setting up the Hardware
Use jumper cables to attach the LED ring as in the image.
Attach the red wire to +5v, the black to ground, and the white data line to GPIO pin 18.
Setting up Node-Red
Start Node-Red and navigate to 127.0.0.1:1880 using the web browser.
Drag in the ‘rpi neopixels’ node; and double click on it to start editing its properties.
Set the LEDs field to the number of LED on the ring: 12. Set the Mode to ‘bar – Number of pixels’. The other fields are all optional, but it might be nice to lower the Brightness, here I lowered it to 15 to lower eye damage. The LED ring can be painfully bright if you are indoors.
Next we drag in the ‘injection’ node, the LED ring node reads strings of text-based commands, and turns them into output on the ring.
We configure our injector like this; setting up Payload to be a string, and contents to be ‘Blue’. Set the checkbox for Inject once after and set the timer to 1 seconds. Repeat can be set to ‘none’.
Connect the two nodes up like this, check your wiring from the start of the tutorial; and then you’re ready to hit Deploy.
If everything is setup correctly the LED ring should display blue within a few seconds.
The command ‘Purple’ sets the background color to purple on the LED ring.
When the LED ring is initialized all the LEDs are changed to the background color, this can also be set in the node preferences as one of the fields we ignored earlier.
If you read the ‘Node Help’ page for the LED ring node you can see further commands.
For example if we change the payload in the injection node to ‘5,Red’ and Deploy then the first 5 LED will be turned Red; the rest of the LED will remain at the background color we can set in the properties field.
Another possible command is a range of pixels, for example the command ‘3,7,Red’ will set pixels 3-7 Red.
The Color names the LED ring will accept can be found here on Wikipedia : https://en.wikipedia.org/wiki/Web_colors
the next step is to connect this knowledge with other tutorials, see other tutorials to maybe connect the LED ring to a physical button, or use it in concert with other outputs like speakers.
More advanced logic can be used to turn the LED ring into a clock, or dial.