deckle studioOpen in the editor

Raspberry Pi Pico: NeoPixel rainbow

WS2812 rainbow via PIO.

  • RP2040
  • WS2812
Open in the simulatorNo account needed: press Simulate and it runs.

How it works

Raspberry Pi Pico (RP2040) with an Arduino sketch: a WS2812B strip with 8 LEDs on GP2 runs a rainbow. The RP2040's PIO block generates the data signal (800 kbit/s); the LEDs decode it from the level and light up in the schematic. The strip runs on 5 V (USB VBUS); the Pico's 3.3 V level is below the WS2812B's VIH (note in the console). Change the sketch in the code editor and start it; the logic analyzer shows the signal on GP2.

Wiring

Each line is one connection (net) and the pins it joins.

NetPins
GNDA1 GNDLED1 GNDVBUS −
5VLED1 5VVBUS +
DINA1 GP2LED1 DIN

Parts

Firmware

sketch.ino · 18 lines

// WS2812B strip (8 LEDs) on GP2: runs as a rainbow. The data comes from the PIO block of the RP2040.
#include <Adafruit_NeoPixel.h>

const int PIN = 2, COUNT = 8;
Adafruit_NeoPixel strip(COUNT, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(80);
}

void loop() {
  static uint16_t hue = 0;
  for (int i = 0; i < COUNT; i++) strip.setPixelColor(i, strip.ColorHSV(hue + i * 65536L / COUNT));
  strip.show();
  hue += 512;
  delay(20);
}
Open in the simulator

More examples: Microcontrollers