Programmable light stick with the Raspberry Pi Pico
Painting with Light
In the photographic method of light painting, you expose a subject over an extended period of time while moving the light sources. With a little technical support from a Raspberry Pi Pico, you can achieve sophisticated results.
Without light, nothing can be seen in photography, but with just a little background light and light brushes, you can create interesting motifs. For long exposures, you need a camera with manual adjustment and a tripod. A flashlight or laser pointer is sufficient to paint simple patterns or lettering into an on-going exposure. If you like to experiment, you might want to work with LEDs to achieve particularly interesting light graphics.
I was interested in a creative approach and in trying out what can be achieved with modern pixel elements and clever programming. The idea of a light stick for light painting was born. In this article, I use a Raspberry Pi Pico to build a MicroPython programmable LED light stick.
The control does not require much in the line of interfaces, and the hardware needs to be as compact as possible – a good fit for the Pico, which is the youngest member in the Raspberry Pi family and has already seen a huge amount of interest in the last months, with some interesting HATs to match. The large community proves to be a boon if you are looking for help. Currently the smallest Raspberry Pi model, the Pico comes with an RP2040 microcontroller chip and an ARM Cortex M0+ processor, offering a state-of-the-art alternative to comparable controllers. It can run C/C++ and performs well with MicroPython.
Light Brush
In this project, I use the MicroPython firmware on the Pi Pico (Table 1). The light stick does not need a WiFi connection. For a project intended for outdoor use, it is convenient to be able to switch off the supply voltage without risking damage to an SD card. I will not be going into the details of how to get started with the Pi Pico, what you need to consider when communicating with the device, and how to program with MicroPython, because enough good articles on these subjects already exist on the web.
Table 1
Materials
Quantity | Item |
---|---|
1 |
Raspberry Pi Pico |
2 |
LED tape WS2812b |
1 each |
Resistors: 460 ohm, 1.2k |
1 each |
Capacitor, 22nF; electrolytic capacitor, 100µF |
1 each |
Switch, button |
2 |
20-pin female connector strip |
1 |
Universal printed circuit board |
4 |
1.2V NiMH batteries (or a 5V battery pack) |
2 |
Aluminum U-section |
|
Wiring and mounting material |
Even a small breadboard offers sufficient space to connect the essential components for some initial tests (Figure 1). The Pico has to control a multitude of RGB LEDs, and the easiest way to implement this is with NeoPixels [1] (e.g., WS2812b), LEDs that have their own control chip and can therefore be addressed individually on the wire. Now available in many designs, they will be referred to in the following text as LEDs for the sake of simplicity.
A light stick length of 2m is fine, so it can be easily transported and, above all, moved. This movement and the timed switching of certain pixels should create a satisfactory curtain of light in the finished photo (Figure 2).
Structure
If the circuit works in the test setup, you can move on to the build. All the hardware is attached directly to the stick, which is created from a standard aluminum U-section. Luckily, the finished board turns out to be relatively compact, because with just a few components, you can work with a universal PCB (Figure 3). Ideally, the Pico will have a slot on the top side so that you can remove the PCB from the rest of the hardware. The Pi Pico is also available as an M version with soldered tips, but only a few pins have to be connected, so you can do the soldering yourself fairly quickly. That's why the board in the figure does not have a continuous socket strip.
Because I wanted to set the light points relatively close together, I decided on a strip with 60 LEDs/m, which results in a total of 120 LEDs. The LEDs require an appropriate power supply, which cannot be taken from the Pico but must be wired directly from the source. With a circuit like this, a small serial resistor in the data line to the LED strip (at GPIO18) is a good idea. Four 1.2V NiMH batteries (micro, AAA) provide power; they can be removed and charged as needed (Figure 4). Alternatively, you could use a power bank (as small as possible) that delivers 5V. At 4.8V, the circuit still works perfectly: The LEDs reach the desired brightness and can be dimmed.
Sometimes long LED arrays will manifest errors, resulting in uncontrolled flashing of the diodes that requires stabilizing the data line and power supply. This problem did not occur with the components I used. The two capacitors in the circuit diagram (Figure 5) are provided as a precaution during alternative operation with a plug-in power supply.
Operation
In the schematic in Figure 5, you can see that T1 and R2 are connected to the GPIO17 pin of the controller. When the light stick is on, processing starts first with the pre-configured light pattern. The push button is the only control element during operation, which is necessary because the camera has to be triggered before the glow stick is used, so everything must be well timed and easy to operate. Later, I will push a button to switch to the next light pattern. The green LED on the board points backward toward the operator when shooting to provide orientation for the various flash codes.
After applying the supply voltage with a toggle switch (S1), the board LED flashes every second under software control, indicating that everything is ready. At the first button press, the flash frequency drops to two seconds, and you now have only a short time to get into recording position. Immediately before the start of the light sequence, the diode flashes very briefly, at which time you have to start moving the light stick. Everyone can create their own sequences with various levels of operating convenience.
The Pico has a control button on-board for switching to mass storage mode. If the microcontroller is connected to the computer over USB, a window with a file manager opens on Linux or Windows, and you can drag and drop source code there. A C/C++ development environment is built in, and Arduino IDE integration works, as well.
The easiest tool for Python development is Thonny [2]. Once the lean IDE (Figure 6) has been set up for the Pi Pico and MicroPython interpreter, communication with the module is automatic. The pleasingly clear-cut editor can be configured in all of its basic features. In the Save dialog, you can choose whether to upload the source code directly to the Pico or store it in a directory, which proves to be particularly useful in practice.
The real creativity in this project lies in the design of the sequences for the light control. The upright light stick maps the lines of the light image virtually as it moves, and you have to consider which LEDs you want to light up and at what intervals, color, and intensity so that they end up painting an interesting picture (Figure 7).
The interesting thing for the developer is that the PIO assembly and up to eight state machines can be defined in MicroPython on the Pico, so all data can be transferred fast enough to the single-wire bus that controls the LED pixels. It is a good idea to follow the documentation first and seek guidance in blogs and wikis.
After a definition block, the next part continues with some functions that update the colors of all or selected pixels – optionally in combination with a list of brightness values as used by the light control. The project source code, which can be found on my GitHub page [3], contains some sample methods, as well as a fair amount of information about the rest of the programming needed.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.