Pico PR

How to use “Serial LED” with RaspberryPi Pico2 ~ MicroPython ~

記事内に商品プロモーションを含む場合があります

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

Not necessarily pico2

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.

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.

Image showing the serial LEDs to be used in this project
BTF-LIGHTING WS2812B

Connecting Pico2 and serial LED

Connect the RaspberryPi Pico2 to the serial LED as follows.

Image illustrating how to connect Pico2 and serial LED

Pin No Name Wiring connections note
1 GP0 DIN
36 3V3 Power
38 GND GND

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.

ノーブランド品
¥1,475 (2024/11/27 21:32時点 | Amazon調べ)

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.

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)

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です。

ABOUT ME
えす
現役のソフトウェアエンジニアです。 C++ C# Python を使ってます。10年ちょい設計/開発部門にいましたが、今はQAエンジニアっぽいことをしています。
Index