MicroPython NeoPixels on a Pico: 8 LEDs on GP16
MicroPython on a Raspberry Pi Pico: the neopixel module fills an 8 LED WS2812 module on GP16 with red, green, blue and white, one LED at a time. The whole build, a Raspberry Pi Pico and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $7. On Mokxi they're free.
What you'll learn
- Addressable LEDs on a single data line
- Colors as red, green, blue triples
- Setting pixels, then calling write
- Looping over a list of names and colors
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Raspberry Pi Pico
- Parts: 3
How it works
Eight RGB LEDs share one data line, DIN, wired to GP16, and they run from 3.3 V. The program fills them one at a time with red, then green, blue and white, and finally with black to turn them off.
Each pixel is set, then write shows it, and the program waits 60 ms before the next one. The levels are only 10 out of 255, because LEDs this close together are bright. It prints the name of each color when it finishes.
Parts list
3 parts, plus the jumper wires. They retail for about $7; on Mokxi they're free.
- 1 × Raspberry Pi PicoIn Fight Stick Kit.
- 1 × Addressable RGB LEDsIn Claw Machine Kit, Halloween Prop Kit, Christmas Lights Kit.
- 1 × Power, 3.3 V
Kits that can build it
These 2 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Addressable RGB LEDs pin DIN | Raspberry Pi Pico pin GP16 |
| Addressable RGB LEDs pin VDD | 3.3 V |
| Addressable RGB LEDs pin VSS | Ground |
The code
The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.
# The 8 RGB LED module on GP16: fill it red, green, blue and white one
# LED at a time, then turn it off. MicroPython's neopixel module sends the
# colors; they are kept dim (10 of 255), as LEDs this close are bright.
from machine import Pin
import neopixel
import time
np = neopixel.NeoPixel(Pin(16), 8)
colors = [("red", (10, 0, 0)), ("green", (0, 10, 0)), ("blue", (0, 0, 10)), ("white", (10, 10, 10)), ("off", (0, 0, 0))]
while True:
for name, color in colors:
for i in range(8):
np[i] = color
np.write()
time.sleep_ms(60)
print(name)
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Nothing lights up. This project
Check DIN goes to GP16, and the count of 8 inNeoPixelmatches your LEDs. - The LEDs are too dim. This project
That is on purpose. Raise the 10 values incolors, up to 255, for more brightness. - The first LED flickers, shows wrong colors, or the whole strip glitches. Addressable RGB LEDs
Join the grounds of the strip and the controller. Add a 300 to 500 ohm resistor in series with the data line. Put a 1000 uF capacitor across the strip's 5 V and GND. - The strip works at low brightness but dims, turns yellow, or resets when many LEDs go white. Addressable RGB LEDs
Each LED can draw about 60 mA at full white. Use a 5 V supply sized for the count, feed power in at several points, and lower the brightness in code. - The Pico does not show up as a drive, or the program will not load. Raspberry Pi Pico
Hold the BOOTSEL button while you plug in USB. A drive named RPI-RP2 appears. Then copy the UF2 file onto it. - A 5 V signal or sensor is wired to a GPIO pin. Raspberry Pi Pico
Pico GPIO pins are 3.3 V only and are not 5 V tolerant. Use a level shifter or a voltage divider for any 5 V output going into the board.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.