Introduction
This blog post explains how to use serial LEDs with the RaspberryPi Pico2 using MicroPython.
Have you ever used single-color or full-color LEDs and thought,
“I want to use more LEDs!
With regular LEDs, the number of LEDs and distribution wires increases, but with the serial LEDs introduced here, you can control many LEDs with only three wires.
It is easy to make multiple LEDs glow, create a stream of light, or create a gradation of light, so please read the article and try your hand at making one.
To make programming easy, we will use the “NeoPixel” library embedded in Micro
The Pico2 is used in this blog post, but the exact same wiring and programme can be used with the Pico and Pico W.
If you don’t have a Pico2 yet, please try it out with your Pico series.
~ この記事の内容 / Contents ~
Environment
The environment used in this blog post is as follows
environment | Version etc. | Comments |
Developing PC | Windows11 | Windows 10’s fine. |
Language | MicroPython Ver.1.24.0 | |
Development Environment | Thonny Ver.4.1.4 | |
board | RaspberryPi Pico2 | Can also use Pico, PicoW |
Serial LED (Tape type)
Serial LEDs are LEDs with several LEDs connected to each other. There are different types, such as ribbon, square and circular.
There are different ways to arrange them, but all types have a small controller (e.g. WS2812B) in common: by sending signals to this controller, the LEDs can be controlled.
As the LEDs are connected to each other by beads, a single signal line can be used to control several LEDs.
In this case, the following serial LED tape ‘BTF-LIGHTING WS2812B’ is used with 60 LEDs connected to the WS2812B controller.
Connecting Pico2 and serial LED
Connect the RaspberryPi Pico2 to the serial LED as follows.
Pin No | Name | Wiring connections | note |
1 | GP0 | DIN | |
36 | 3V3 | Power | |
38 | GND | GND |
The serial LED used in this project comes with a breadboard conversion connector that leaves the wire ends as they are.
This wire looks like a “single wire”, but it is actually a “twisted wire”. The ends are just soldered on, so be careful not to peel off the sheath if you want to make it longer, as it will not fit on the breadboard.
Note the number of LEDs to be lit.
The maximum output current of the Pico series is low, and the program (firmware) may hang if the output current becomes too high.
If you want to increase the number of LEDs to be lit, use another 3.3V power supply, such as a battery, connected to the following branched wiring.
Parts in use
RaspberryPi Pico 2
If you’re getting a Pico now, we recommend the Pico2 – it’s 1.5 times faster than the Pico and almost the same price.
Ready-to-use kits are also available.
Ready to use kits with soldered headers, USB cable and pin layout chart are also available.
Serial LED (Tape type)
This is the serial LED used in this project. It has a WS2812B as a controller. The one used in this article was also purchased from the following link.
It arrived tightly packed in a ziplock-like gusseted bag with no broken or defective wires.
Breadboard
This breadboard is made by San Hayato in Japan. It is a bit stiff to point at, but unlike the Chinese ones, all the pinhole numbers are printed on the board and are of high quality, so it is recommended.
jumper wire
This kit contains a set of hard jumper wires. It can make a cleaner circuit than soft wiring.
Jumper wire (for self-production)
The kit doesn’t have the right length or colour. You can make your own with the following wiring. The wires are almost as stiff as jumper wire, so you can make an ideal jumper wire just by cutting and bending.
Programme overview.
The following is an overview of the code.
- NeoPixel library settings
- Turn on each LED
Serial LED Library
NeoPixel” is used as a library to easily handle serial LEDs.
There is a lot of information on the net about using this library for board-type serial LEDs, but it can be used for tape-type LEDs as well.
It is also included by default in the MicroPython firmware of the Pico series, so no additional installation is required.
The results of running the programme
The following is the result of running the program described
Entire code
The full text of the Code is as follows. The details are explained in the section “Key Points of the Code” below.
import machine, neopixel, time
# NeoPixcel set up with pin numbers and number of LEDs
np = neopixel.NeoPixel(machine.Pin(0), 60)
for loop in range(100):
# Loop by number of LEDs
for i in range(60):
# Set all lights off
for cnt in range(60):
np[cnt] = (0, 0, 0)
# Turn an LED to blue.
# Specify colors in the order G, R, B
np[i] = ( 0, 0, 255)
# Write (send signal) to serial LED
np.write()
# 0.05 sec. wait
time.sleep(0.05)
# Wait 0.1 second after 60 LEDs light up
time.sleep(0.1)
To run the program with the Pico series alone (without Thonny), save the program as “main.py” in the Pico series main unit.
Key Points of the Code
NeoPixel library settings
Configures settings for the NeoPixel library.
The argument specifies the Pico pin name (GPxx) to connect to the LED signal line (DIN) and the total number of LEDs to drive.
# NeoPixcel set up with pin numbers and number of LEDs
np = neopixel.NeoPixel(machine.Pin(0), 60)
LED Lighting
To make it look like the glowing LEDs are moving, they are turned on by moving their positions one by one.
Once an LED is turned on (set to a value), it stays that way, so after it is turned on, the contents of the np array are turned off with (0,0,0) before the next LED is turned on.
for loop in range(100):
# Loop by number of LEDs
for i in range(60):
# Set all lights off
for cnt in range(60):
np[cnt] = (0, 0, 0)
# Turn an LED to blue.
# Specify colors in the order G, R, B
np[i] = ( 0, 0, 255)
# Write (send signal) to serial LED
np.write()
Finally
I explained how to use serial LEDs with RaspberryPi Pico2 using MicroPython.
However, lately I have been seeing more and more off-the-shelf serial LEDs around town,With the Pico series, you can make serial LEDs glow with “original” patterns that off-the-shelf LEDs cannot.
It is easy to use and stands out from the crowd, so I encourage everyone to give it a try.
I would be happy to help.
質問・要望 大歓迎です
「こんな解説記事作って」「こんなことがしたいけど、〇〇で困ってる」など、コメント欄で教えてください。 質問・要望に、中の人ができる限り対応します。
使えたよ・設定できたよの一言コメントも大歓迎。気軽に足跡を残してみてください。記事を紹介したい方はブログ、SNSにバシバシ貼ってもらってOKです。