Reference
NeoPixel
WS2812B addressable RGB LEDs.
- Connects over
- GPIO pins
- Made by
- Worldsemi (WS2812 / WS2812B / SK6812)
- Datasheet
- cdn-shop.adafruit.com
Use it
hardware {
device neopixel: NeoPixel(pin: 16, leds: 8)
}
every 1s {
neopixel.set(1, 1, 1, 1)
}
The NeoPixel is wired to ordinary GPIOs: give each of its pins (pin) as a named argument. The compiler checks every pin can do its job.
Methods
-
neopixel.set(index: int, r: int, g: int, b: int)
Set pixel color
-
neopixel.clear()
All pixels off
-
neopixel.fill(r: int, g: int, b: int)
Fill all pixels
-
neopixel.show()
Update LED strip
-
neopixel.set_brightness(brightness: int)
Global brightness 0-255
Wiring
| Pin | Connect to |
|---|---|
VCC | 5V — beefy supply if you have many LEDs (60 mA each) |
GND | Common with MCU ground |
DIN | Add a ~300Ω series resistor; level-shift to 5V if MCU is 3.3V (74AHCT125) |
DOUT | Feeds the next LED's DIN — chain as many as your power supply can handle |
Specifications
- Voltage
- 4.5V – 5.5V (some 3.3V variants exist — see SK6812)
- Current
- ≈ 60 mA per LED at full white
- Data rate
- 800 kHz NRZ — strict timing
- Color depth
- 24-bit (8 per RGB channel) or 32-bit on SK6812 RGBW
Tips
- Add a 1000 μF capacitor across VCC/GND at the strip input — prevents the inrush spike from killing the first LED.
- Level-shift the data line — 3.3V MCUs are borderline for a 5V WS2812; failures are intermittent and maddening.
- Disable interrupts during transmission if the MCU is busy — even a few μs of pause corrupts the frame.
- First LED is often DEAD on cheap strips — solder a header to feed past it.
Alternatives worth knowing:
- SK6812: RGBW variant (adds a white channel) — same protocol.
- APA102: SPI-style two-wire (clock + data) — no timing constraints, more robust on Pi/Linux.