Header Ads Widget

WS2812 Neopixel LED with Raspberry Pi Pico

In this tutorial, I will guide you to connect WS2812 Neopixel Leds or Neopixel rings with Raspberry Pi Pico using Micropython running on a Pico board to show various colors.

About ws2812 as per datasheet :

WS2812 is an intelligent control LED light source that the control circuit and RGB chips are integrated into a package of 5050 components. It internally includes an intelligent digital port data latch and signals reshaping amplification drive circuit. Also include a precision internal oscillator and a 12V voltage programmable constant current control part, effectively ensuring the pixel point light color height is consistent.

The data transfer protocol uses a single NZR communication mode. After the pixel power-on reset, the DIN port receives data from the controller, the first pixel collects initial 24bit data and then sent to the internal data latch, and the other data which is reshaped by the internal signal reshaping amplification circuit sent to the next cascade pixel through the DO port. After transmission for each pixel, the signal is reduced to 24bit. pixel adopt auto reshaping transmit technology, making the pixel cascade number not limited to the signal transmission, only depending on the speed of signal transmission.


For this tutorial, I am going to connect the VBUS pin of Raspberry Pi Pico to the VCC Pin of WS2812 or Neopixel Led, GND to GND of Pico, and Data Pin of ws2812 to Pin 6 Of Raspberry Pi Pico. You can refer to the image below for the same.

Source Code

This code is for controlling a strip of WS2812 LEDs using a Raspberry Pi Pico microcontroller. The code sets up a StateMachine using the rp2 library to control the LEDs, and then defines a number of functions for displaying different patterns on the LEDs such as setting individual pixels to a certain color, filling all the pixels with a certain color, chasing a color through all the pixels, and cycling through a rainbow of colors.

There is also a while loop at the end that sets the second and fourth pixels to red and blue respectively and displays them on the LEDs with a short delay in between. This loop will run indefinitely, continuously displaying the two pixels in red and blue.

Post a Comment