Maker Portal

View Original

WS2812 LED Ring Light with Raspberry Pi Pico

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

See this content in the original post

See this content in the original post

A 16-pixel LED ring light is recommended when using just the Raspberry Pi Pico microcontroller. If a larger pixel LED ring light is used, then an external power supply should be used in order to reduce the load requirement from the USB port. This is why a general 5V external supply is used in the wiring diagram for this project - it will allow users to use nearly any LED ring light with any number of pixels (with some caveats related to addressing the pixels). The full list of components used in this tutorial are given below:

  • Raspberry Pi Pico Starter Kit - $15.00 [Our Store]

  • 16-Pixel RGB LED Ring Light - $15.00 [Our Store]

  • 5V 3A Power Supply - $9.99 [Amazon]

  • Raspberry Pi 4 Computer - $58.99 (2GB), $61.50 (4GB), $88.50 (8GB) [Amazon], $55.00 [2GB from Our Store]

Note that the 5V 3A supply was chosen to handle ring lights that contain up to 85 pixels (based on the measured maximum current of 35mA for each LED). We were able to test 60 LEDs with the 5V/3A power supply without issue.

See this product in the original post

A pinout diagram for the Raspberry Pi Pico can be found here. The wiring diagram between the Raspberry Pi Pico and WS2812 RGB LED ring light is given below:

Note the use of the DI pin as the control pin for the WS2812 LED. The 5V is supplied by the external supply, and the Raspberry Pi, ring light, and external supply all share a ground. The DO pin on the ring light allows users to connect multiple assemblies of LEDs, but will not be used or discussed further in this tutorial. Technically, VBUS on the Pico (pin 40) is capable of supplying 0.5A (USB 2.0) or 1.0A (USB 3.0), thus, the 16-pixel LED ring light can be powered via the VBUS pin, however, it is safest to use either USB 3.0 or an external supply.

Below is a photo of the multimeter amperage output of the 16-Pixel LED Ring Light at maximum brightness for all 16 LEDs:

Based on the 0.55A measurement of the LED ring light at maximum brightness (shown above) — the average maximum for each LED is approximated as ≈35mA. In the next section, the MicroPython code framework for controlling the LEDs will be introduced along with a simple routine that creates a rotating pixel color. The Raspberry Pi Pico will be used along with Thonny to program the 16-Pixel Ring Light in real-time.

See this content in the original post

See this content in the original post

The 16-Pixel LED Ring Light will be controlled using the scheme outlined in the Raspberry Pi Pico MicroPython getting started document, where a tutorial entitled “Using PIO to drive a set of NeoPixel Ring (WS2812 LEDs)” contains a script that we will use to create a state machine on the RPi Pico. The state machine will be used to control the LEDs on the ring light using just a single pin on the Pico (GPIO13 as wired above). A full MicroPython example script can also be found at the Raspberry Pi Pico’s NeoPixel Ring repository on GitHub. Some of the algorithms that follow are not contained within that repository, but are included in the GitHub repository for this tutorial:

The code to start the state machine on the RPi Pico's GPIO pin #13 is given below:

See this content in the original post

This snippet of code is the header for all algorithms to follow. The variable led_count = 16 states that we will be using a 16-pixel WS2812 LED ring light. PIN_NUM = 13 defines GPIO13 as our control pin, and brightness is used to dim the LEDs (1 = max brightness). The state_mach houses the state machine on GPIO13 at the allocations contained within ws2812. Finally, the last line in the code above activates the state machine and waits for changes to be implemented.

Another snippet of code is given below that loops a single color LED around the 16-pixel ring light:

See this content in the original post

Below is a video demonstration of the code above, showing the single looping LED:

The above is one of the simpler routines that we can do with the 16-pixel ring light.

Another fairly simple algorithm that we can try is a ‘breathing’ type LED routine that entails going from minimum to maximum brightness and back to minimum brightness. This results in a light-based ‘breathing’ that looks similar to some of those employed by the Amazon Alexa devices. The code is given below followed by another GIF demonstration:

See this content in the original post

In the next section, a more in-depth example will be explored by creating a Google Home LED emulator.


See this content in the original post

At this point, the user should be comfortable with the functionality of the WS2812 LEDs and how to control the ring lights with the Pico state machine. In this section, we will be attempt to emulate the Google Home quad-LED rotating function, the Amazon Alexa’s rotating blue LED curve, and the Amazon Alexa’s zipped off function.

Below is the script used to carry out all three functions stated above:

See this content in the original post

In the code above, the user may notice that hex colors are being used as opposed to the RGB values from 0-255. This is simply due to the commonality of hex colors in brand colors. For Google we’re using four of their specified brand colors (taken from the Google.com logo):

See this content in the original post

These four colors will be placed 90-degrees from one another in order to emulate the Google Home LED display. If users are unaware of the Google Home LED routines, see this page for reference.

Below is a snippet of the code used to loop the four 90-degree LEDs to emulate the Google Home clockwise:

See this content in the original post

Note that we are selecting only four LEDs and coloring them as the four Google colors. Then, we rotate them around the circle. To emulate the Alexa, we can use similar methods — all of which are given in the full code above and on the GitHub page for the project. Below is a snippet of the turnoff function used in Amazon Alexa devices, which is just a slight variation of the ‘chase’ style turnoff:

See this content in the original post

Below is a video demonstration of the Google and Amazon emulator created with the Raspberry Pi Pico and 16-pixel WS2812 ring light:

See this content in the original post

It is also noticeable that the LED colors do not quite match those depicted on computer screens. This is due to several reasons. First, the WS2812 LEDs are larger than display LEDs and the LEDs used in the Google Home and Amazon Alexa. This results in a less defined color where the red, blue, and green are more visible. Another reason for the color disparities is the use of the translucent dome, which may refract certain colors of light being emitted by the WS2812 LEDs.


See this content in the original post

In this second entry into the exploratory series of the Raspberry Pi Pico, a 16-Pixel RGB LED Ring Light was controlled using a state machine in MicroPython. Several different algorithms were outlined to emulate the Google Home color scheme, the Amazon Alexa LED schemes, and other unique color array methods. The LEDs used are similar to the widely available WS2812 RGB LEDs, which consume roughly 35mA each. The 16-pixel ring light was able to be safely powered via the VBUS pin on the Pico, which takes power directly from the USB 3.0 port on a Raspberry Pi 4 computer. This tutorial was meant as a further introduction to the Raspberry Pi Pico with MicroPython. This is only the second entry into a serial, where we focused on unique algorithms meant to push the limits of the Pico control of the ring light. This tutorial series will continue with further explorations of the Pico, with extensions into reading sensors, using different digital protocols such as UART, SPI, I2C, and other ways of testing the limits of the Pico microcontroller.

Zoomed-in view of a single RGB LED aboard the 16-pixel ring light.

See this content in the original post

See More in Raspberry Pi Pico and Microcontrollers:

See this content in the original post