Programmable light stick with the Raspberry Pi Pico

Painting with Light

© Photo by Xuan Nguyen on Unsplash

© Photo by Xuan Nguyen on Unsplash

Article from Issue 256/2022
Author(s):

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.

Figure 1: The circuit built on a breadboard for the initial tests.

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).

Figure 2: Painting in the air: light painting with the LED light stick and Pi Pico.

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.

Figure 3: On the left side of the control board is an on-off switch and a push button.

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.

Figure 4: The control board and the batteries are positioned on the back of the light stick.

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.

Figure 5: The button (T1) in the circuit diagram is the only control element for the light bar.

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.

Figure 6: The simple, well-structured Thonny development environment with the source code for the project.

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).

Figure 7: All 120 LEDs of the light stick can be controlled independently.

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

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Greenhouse Control

    You can safely assign some greenhouse tasks to a Raspberry Pi Pico W, such as controlling ventilation, automating a heater, and opening and closing windows.

  • Pico Sleep Mode

    The Raspberry Pi Pico's high-performance chip is trimmed for I/O and does not try to save power. However, a few tricks in battery mode can keep it running longer.

  • Web Serial API

    Upgrade your computer with LEDs, buttons, or sensors to control a microcontroller board over USB from your web browser.

  • BBC micro:bit

    Designed for students, the BBC micro:bit, in conjunction with MicroPython and the Mu editor, can help you get started with microcontroller programming.

  • ESPHome

    With an ESP32 or Raspberry Pi Pico W microcontroller board, you can easily create your own home automation devices. Thanks to ESPHome, you don't even have to be a programmer.

comments powered by Disqus
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.

Learn More

News