NeoPixel stick (8)
A NeoPixel stick is a row of eight WS2812B LEDs, each with its own driver chip, sharing one data line. It costs $7 and lets you set every pixel to any colour independently — chase effects, level meters, status bars — with a single GPIO. Colour data is shifted down the line at 800 kHz; each LED keeps the first 24 bits it sees and forwards the rest.
Pins
| Pin | What it is | Type |
|---|---|---|
| DIN | Data in (800 kHz) | io |
| 5V | Supply 5 V | power |
| GND | Ground | ground |
| DOUT | Data out, to the next board's DIN | io |
DIN takes the data stream from the Pi, DOUT repeats it for the next board in the chain, and 5V/GND power the LEDs. The data line is not a pin you can bit-bang casually: on a Pi the neopixel library drives it with PWM/DMA on GPIO18 (GPIO10 or GPIO12/21 also work), which is why the stick belongs on GPIO18.
Wiring it in circuit.py
from wiring import *
pi = Pi()
stick = NeoPixelStick()
pi.GPIO18 >> stick.din # the data line must be GPIO18 (PWM) on a real Pi
pi.V5 >> stick.v5 # 5 V supply for the LEDs
stick.gnd >> pi.GNDTo chain a second board, wire the first board's DOUT to the next one's DIN; the pixels then continue at index 8. Both boards can share the 5 V and GND rails.
Driving it in main.py
import board
import neopixel
from time import sleep
pixels = neopixel.NeoPixel(board.D18, 8, auto_write=False)
pixels.brightness = 0.3 # keeps the power budget and your eyes happy
while True:
for led in range(8):
pixels.fill((0, 0, 0))
pixels[led] = (255, 0, 0)
pixels.show()
sleep(0.1)Set auto_write=True (the default) to have every assignment call show() immediately. Slicing works too: pixels[0:4] = (0, 64, 0) fills the first four pixels.
Electrical notes
- Each LED draws up to 60 mA at full white (20 mA per channel) plus about 1 mA idle, all from 5 V. Eight LEDs at full white are about 480 mA — more than a Pi 5 V header should be asked for continuously. Keep brightness down, light few pixels, or feed the stick from a separate 5 V supply with a shared ground.
- The data line expects at least 3.5 V at a 5 V supply. A 3.3 V GPIO usually works over short wires, but a level shifter is the reliable answer on a bench.
- Data order is GRB, not RGB. The simulator enforces that, so a
pixel_order=RGBmistake swaps red and green on the canvas just like on hardware. - Reverse polarity or 5 V on the data pin damages the LEDs; wire
5Vbefore testing data.
Simulator vs real hardware
- The model consumes the first
8 × 3bytes of the stream and hands the rest toDOUT, so chained boards behave like one long strip. - Power is modelled as
1 mA per LED + channel sum ÷ 255 × 20 mA; above 1 000 mA the part warns, which on a Pi 5 V rail is a hint to use a separate supply rather than a judge failure. - Timing, protocol bits and root access are abstracted away:
show()reaches the pixels instantly, and the canvas paints each one. There is no flicker, refresh rate or DMA limit to fight. - The real thing needs root (
rpi_ws281xbehindneopixel), a 3.5 V-compatible data signal, and enough 5 V current for the colours you ask for.
Going deeper
- NeoPixel ring (12) — the same API in a circle.
- neopixel library and gpiozero.
- Recipe: the NeoPixel level meter drives the stick from a sensor.
- Powering concerns are the same as any 5 V load: see power supply.
Further reading
- WS2812B datasheet (Worldsemi) — timings, GRB order and current per channel.
- Adafruit CircuitPython NeoPixel API — the
NeoPixelAPI the simulator implements. - Adafruit: NeoPixels on Raspberry Pi — wiring, power and the real Pi requirements.