MicroPython – WS2812 aka NeoPixel

Adding Color

© Chris Barbalis on Unsplash

© Chris Barbalis on Unsplash

Article from Issue 300/2025
Author(s):

The Adafruit NeoPixel (WS2812) is an RGB LED that you can program via a serial protocol. We show you how to control the LED with a few lines of MicroPython.

The WS2812, also known as the Adafruit NeoPixel, is a programmable RGB light-emitting diode (LED). It consists of a controller and three LEDs in the colors red, green, and blue. There is a data byte in the controller for the brightness of each individual LED. This means that a NeoPixel can display up to 16,777,216 colors. NeoPixels are available both as a single component and pre-installed on various carriers. The best-known forms include the LED strip, the matrix, and rings [1] of various sizes.

Each NeoPixel has four connectors, two of which are for the 5V operating voltage. The other two connectors DI (Data In) and DO (Data Out) are used for asynchronous serial data transmission. The output (DO) of one WS2812 can be connected to the input (DI) of the next WS2812, so in theory, you can create an arbitrarily long chain of NeoPixels. One thing you need to bear in mind, though, is that data transmission can take a while. If it takes too long, the LEDs will start to flicker. But if you have 1,024 LEDs in series, it is still possible to supply them with data 30 times per second, and flicker is undetectable for us humans at this frame rate.

The signal for controlling the LEDs has a very special structure: The individual data bits are coded with a pulse width modulation (PWM) signal. The pulse-pause ratio of the signal defines whether it is a one or a zero. This method reduces susceptibility to interference. To avoid overloading this text with technical details, I'll just point you in the direction of the WS2812 data sheet [2] instead. It describes precisely how the protocol works, and it has the full details of the WS2812.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Christmas Tinkering

    Make your own Christmas music box with a microcontroller, servomotor, NeoPixel LED ring, and mini-MP3 player.

  • Light Painting

    In the photographic method of light painting, you expose a subject over an extended period of time while moving the light sources. With a little technical support from a Raspberry Pi Pico, you can achieve sophisticated results.

  • Arduino CLI

    When programming an Arduino microcontroller board for the first time, most people use the Arduino IDE, a graphical development environment. However, if you prefer the command line, you have a powerful alternative: Arduino CLI.

  • Low-Code with Snap4Arduino

    Snap4Arduino brings the power of low-code programming to the Arduino hardware environment.

  • Snek

    Reuse your old Arduino hardware while learning Python.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News