LED Strip
Introduction
Section titled âIntroductionâBefore thinking about the hardware or the software needed to light-up a LED strip, itâs mandatory to talk about the different driver chips used to control the LEDs.
WS2811 VS WS2812
Section titled âWS2811 VS WS2812âThe main differences are summarized into different categories:
- Power:
WS2811
LED chip needs a voltage of12V
to work, whileWS2812
chip only uses5V
. - LEDs Controlled:
WS2811
actually do not control one LED, but instead it controls a cluster of3
LEDs together.WS2812
can control1
LED each.
Software Setup for Python
Section titled âSoftware Setup for PythonâOne of the best environments for Python programming (and definitely my favorite) is PyCharm by JetBrains. However, PyCharm is not really suitable for running python scripts from the Raspberry Pi board, since itâs very resource-consuming.
Some light-weight IDEs are:
- Visual Studio Code which is also available for Raspberry PI by following this guide
- Thonny which is installed by default on Raspberry Pi OS
- Mu
Hardware requirements & setup
Section titled âHardware requirements & setupâ- Raspberry Pi 4 board or any other Raspberry Pi board
- LED strip, suggested stores are:
470 Ohms
resistor- Hook-up wires of different colors
- Breadboard
- 12V power supply if using a strip controlled by
WS2811
chip
In this schema, I do not event used the resistor since Adafruit strip already has it built-in. Moreover, the strip is powered at 5V
so I do not even need an external supplier.
Please Note: NeoPixels must be connected to GPIO10
(user defined), GPIO12
, GPIO18
or GPIO21
to work.
Software requirements & setup
Section titled âSoftware requirements & setupâLetâs follow the CircuitPython on Linux and Raspberry Pi guide to set everything up!
Please Note: At this time, Adafruit does not support the 64-bit
version of Raspberry Pi OS so letâs find out which version weâre currently running.
Open a Terminal and type:
uname -m
If your machine is running a 32-bit
OS version, the output will be i686
or i386
or armv7l
. While if your machine is running a 64-bit
OS version, the output will be x86_64
or armv8
.
# update the Raspberry Pi and Pythonsudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip
sudo pip3 install --upgrade setuptools
Adafruit also put together a script to easily make sure your Pi is correctly configured and install Blinka
. It requires just a few commands to run. Most of it is installing the dependencies.
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py
If your system default Python is Python 2 (which is likely on a first install), it will ask to confirm that you want to proceed. Choose yes
.
It may take a few minutes to run. When it finishes, it will ask you if you would like to reboot. Choose yes
.
Once it reboots, the connection will close. After a couple of minutes, you can reconnect.
Please Note: Python2 support has been dropped, so you will need to either use pip3
and python3
as commands or set Python 3 as the default python install.
NeoPixel with CircuitPython
Section titled âNeoPixel with CircuitPythonâTo install the python library to drive the NeoPixel LEDs just type:
sudo pip3 install adafruit-circuitpython-neopixel
The common code for all the following effects made with NeoPixel
library with CircuitPython
is:
import timeimport boardimport neopixel
# board pinpixel_pin = board.D10
# the number of NeoPixelsnum_pixels = 100
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.ORDER = neopixel.RGB
pixels = neopixel.NeoPixel( pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER)
# utility functionsdef show_strip(): pixels.show()
def set_pixel(pixel_number, red, green, blue): pixels[pixel_number] = (red, green, blue)
def set_all(red, green, blue): pixels.fill((red, green, blue))
# define the effectdef my_effect(): pass
while True: # run the effect my_effect()
Effects
Section titled âEffectsâYou can take all the sketches from:
led-strip
directory fromarduino-projects
GitLab repository- Raspberry Pi LED Strip Project
Jump to effects
folder to see the list of effects in both the repositories.
Fill free to send me a pull request if you have any suggestion for the effects I could add or improve.
Here is the list:
- BouncingBalls
This effect looks best with the LED strip vertical, and shows one or more bouncing balls in a given color.
- BouncingRGBFade
This effect uses a sequence of fixed colorsâ list for all LEDs: red, green and blue. It slowly increases brightness and when the maximum brightness has been reached, it starts decreasing the brightness again until the LEDs are all OFF.
- ChasingLight
A backhoe of LEDs moves forward and then downward the strip. Each LED is colored with a different composition of the red, green and blue components.
- ColorWipe
You can define different colors that will fill the whole strip, from the first to the last. When a color lights-up all the LEDs, the next color starts over the strip to replace the previous color. You can also allow the color to fill the strip form the last to the fist element using
reverseColorWipe
method.
- FadeInFadeOut-ColorAndBrightness
It fades in and out both color and brightness of the colors you want.
- FadeInFadeOut-ColorWithoutBrightness
It fades in and out color and fakes the fade of the brightness. It is very similar to the effect above.
- Fire
This effect is adapted from an example from
FastLED
, which is adapted from work done by Mark Kriegsman (called âFire2012â). It looks awesome when using diffuse light!
- MeteorRain
This effect looks better with the whole strip placed in vertical position. It creates a meteor that runs through the sky with some randomness LEDs switched on for the tail.
- MultiColor-BouncingBalls
This is a more complex variant of the Bouncing Balls effect. Instead of just one color, it allows the use of multiple colors. This makes the function call a little more complex, since it works for any number of balls youâd like set. To pass the color for each ball you will have to define a multidimensional array filled with the RGB backhoe of each balls.
- NewKITT
This effect follows this pattern:
<---------
--------->
----><----
<---------
--------->
<---------
----><----
<-------->
Inspiration for this effect was taken from
instructables
â article The KITT-duino DIY Larson Scanner.
- RainbowCycle
Fills all the LDEs with different shades of rainbow colors and slowly moves the colors from the start to the end of the strip. It also looks good on a LED matrix like this Flexible 8x8 NeoPixel RGB LED Matrix from adafruit.com.
- RandomColorTwinkle
This is a variation on the Twinkle effect. The only difference is that the colors are now randomly generated.
- RunningLights
This effect makes multiple groups of LEDs chase each other.
- Scanner
This effect mimics the LED of a scanner that runs forward (and downward) the length of the document to scan.
- Strobe
This effect turn the strip in a stroboscopic light. Please Note:
Strobe
effect could lead to epilepsy phenomena in photosensitive subjects.
- TheatreChase
With this effect LEDs are chasing each other like what youâd see in an old Theatre.
- TheatreChaseRainbow
This effect combines RainbowCycle and TheatreChase.
- Twinkle
This effect will blink one or more LEDs in a given color.
Conclusion
Section titled âConclusionâHere we are, at the end of this long blog post. Here are some ideas where you could use those effects:
- smart home with adaptive lights
- alarm system
- notification system
- party lights
Hope you enjoyed this post as much I loved write it. It does not matter weather you prefer to use Arduino or Raspberry Pi or any other board to light up a LED strip.
Keep in mind that there is always a way to do what you want to do.
Documentation
Section titled âDocumentationâSome useful links: