Chapter 6: NeoPixel – Driving WS2812 LEDs with RP2040 PIO in Ada

Hello everyone,

I have just published Chapter 6: NeoPixel of the Raspberry Pi Pico Ada Tutorial.

In this chapter I go beyond the usual “just use the library” approach and explain how the WS2812 protocol actually works and why the RP2040’s PIO is perfect for it. You will see:

  • A simple square-wave generator used as a learning and debugging tool
  • The four gotchas that had me staring at the oscilloscope for far too long
  • A corrected and fully commented version of Jeremy Grosser’s ws2812_demo
  • Two complete animation sketches (Sketch_06_1_LED_Pixel and Sketch_06_2_Rainbow_Light)

The chapter also contains a practical introduction to PIO programming and shows how to generate Ada code automatically with the official pioasm tool.

New GNATdoc documentation is available for both Pico and Pico 2:

Don’t forget the Side Quests either — they cover system setup, Alire, Visual Studio Code, hardware debugging, adding a reset button, and more.

As always, the full source code is on SourceForge and available as an Alire crate (in a few days).

Feedback and questions are very welcome!

Happy hacking, Martin

4 Likes

When setting up a new shot I accidentally pluggedone the older (non-polarity-protected) 8-LED circular NeoPixel modules in the wrong way — data-in into V+, V+ into ground, and ground into an empty slot. It died instantly. :sob:

I lost an led in a led matrix this way :grimacing:
Luckily those are cheap but that still sucked. Learned to check the polarity twice!

1 Like