Skip to content

neopixel: add PIO-based WS2812B driver for RP2040/RP2350#849

Closed
gandarez wants to merge 1 commit intotinygo-org:devfrom
gandarez:feat/neopixel
Closed

neopixel: add PIO-based WS2812B driver for RP2040/RP2350#849
gandarez wants to merge 1 commit intotinygo-org:devfrom
gandarez:feat/neopixel

Conversation

@gandarez
Copy link
Copy Markdown
Contributor

@gandarez gandarez commented Mar 27, 2026

Summary

  • Adds a new neopixel package that provides an Adafruit NeoPixel-like API for WS2812B RGB LED strips
  • Uses PIO (via tinygo-org/pio) for hardware-timed control on RP2040/RP2350, fixing the issue where the existing ws2812 bit-bang driver fails on RP2350's Cortex-M33
  • Falls back to the existing ws2812 bit-bang driver on all other platforms
  • Includes an example targeting the Waveshare RP2350-LCD-1.47 board (GP22, 1 LED)

Motivation

The existing ws2812 driver uses CPU-timed bit-banging assembly tuned for Cortex-M0+. The RP2350's Cortex-M33 has a write buffer and different pipeline that breaks the nanosecond-level GPIO timing. The Arduino Adafruit_NeoPixel library works on the same hardware because it uses PIO.

API

pixel, err := neopixel.New(machine.GP22, 1)
pixel.SetBrightness(50)
pixel.SetPixel(0, color.RGBA{R: 255})
pixel.Show()
pixel.Fill(color.RGBA{G: 255})
pixel.Clear()

Test plan

  • tinygo flash -target=pico2 ./examples/neopixel/ — verify LED cycles Red → Green → Blue on Waveshare RP2350
  • Verify brightness control matches Arduino behavior at brightness=50
  • Verify fallback compiles on non-RP targets

🤖 Generated with Claude Code

The existing ws2812 bit-bang driver fails on RP2350 (Cortex-M33) due to
timing differences from M0+. This adds a neopixel package that uses PIO
via tinygo-org/pio for hardware-timed LED control on RP2040/RP2350, with
a fallback to the ws2812 bit-bang driver on other platforms.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gandarez gandarez changed the base branch from release to dev March 27, 2026 20:10
@soypat
Copy link
Copy Markdown
Contributor

soypat commented Mar 28, 2026

Looks good! Ready to merge?

@deadprogram
Copy link
Copy Markdown
Member

@gandarez I just wonder if this might be able to be added directly to the existing ws2812 driver instead of adding another driver. I have not looked but seems like with the correct build tags you could bypass the CPU and use the PIO code in this PR instead.

What do you think?

@gandarez
Copy link
Copy Markdown
Contributor Author

Let me check if it's possible

@gandarez
Copy link
Copy Markdown
Contributor Author

Closing due to #851

@gandarez gandarez closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants