Pico W WS2812 strip of eight on GP0
MicroPython on a Pico W: the neopixel module gives each of eight WS2812 pixels on GP0 its own color, then turns the colors along the strip. The whole build, a Raspberry Pi Pico W 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 $9. On Mokxi they're free.
What you'll learn
- Addressable LEDs on one data pin
- Setting pixels, then showing them with write
- Colors as red, green, blue triples
- Rotating a list to animate
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Raspberry Pi Pico W
- Parts: 3
How it works
Eight WS2812 pixels sit on one data line, DIN, wired to GP0. The strip is powered from 5 V. Each pixel keeps whatever color it was last sent.
The program sets eight colors, from red through orange, yellow, green, cyan, blue and violet to white, and calls write to show them. Then every 2 seconds it shifts the list of colors one place and writes again, so the colors seem to turn around the strip.
Parts list
3 parts, plus the jumper wires. They retail for about $9; on Mokxi they're free.
- 1 × Raspberry Pi Pico W
- 1 × Addressable RGB LEDsIn Claw Machine Kit, Halloween Prop Kit, Christmas Lights Kit.
- 1 × Power, 5 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 W pin GP0 |
| Addressable RGB LEDs pin VDD | 5 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.
# RGB LED strip: eight WS2812 pixels on GP0. MicroPython's neopixel
# module sends them their colors; write() shows what was set.
from machine import Pin
import neopixel
import time
strip = neopixel.NeoPixel(Pin(0), 8)
colors = [(64, 0, 0), (64, 32, 0), (64, 64, 0), (0, 64, 0),
(0, 64, 64), (0, 0, 64), (32, 0, 64), (64, 64, 64)]
for i, c in enumerate(colors):
strip[i] = c
strip.write()
print("eight colors")
while True:
time.sleep(2)
colors = colors[1:] + colors[:1] # turn the colors one place
for i, c in enumerate(colors):
strip[i] = c
strip.write()
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The strip stays dark. This project
Check DIN is on GP0, VDD is on 5 V and VSS is on ground. - The strip shows old colors after you change the list. This project
Settingstrip[i]only stores the color. Callstrip.write()to show it. - 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. - Pins are powered from 5 V, or a 5 V signal goes into a GPIO. The RP2040 pins are 3.3 V only and are not 5 V tolerant. Raspberry Pi Pico W
Power the board from VBUS or VSYS at 5 V, but keep GPIO signals at 3.3 V. Use a level shifter or a divider for 5 V parts. - WiFi code fails to connect, or the on-board LED code does nothing. The LED on the Pico W is not on GP25 like on the plain Pico. Raspberry Pi Pico W
Use the board's LED_BUILTIN name so the library drives it through the WiFi chip. Join a 2.4 GHz network only, with the right SSID and password, and wait for the link before sending.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.