MicroPython – WS2812 aka NeoPixel
Adding Color

© Chris Barbalis on Unsplash
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.
[...]
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.

News
-
Cairo Dock 3.6 Now Available for More Compositors
If you're a fan of third-party desktop docks, then the latest release of Cairo Dock with Wayland support is for you.
-
System76 Unleashes Pop!_OS 24.04 Beta
System76's first beta of Pop!_OS 24.04 is an impressive feat.
-
Linux Kernel 6.17 is Available
Linus Torvalds has announced that the latest kernel has been released with plenty of core improvements and even more hardware support.
-
Kali Linux 2025.3 Released with New Hacking Tools
If you're a Kali Linux fan, you'll be glad to know that the third release of this famous pen-testing distribution is now available with updates for key components.
-
Zorin OS 18 Beta Available for Testing
The latest release from the team behind Zorin OS is ready for public testing, and it includes plenty of improvements to make it more powerful, user-friendly, and productive.
-
Fedora Linux 43 Beta Now Available for Testing
Fedora Linux 43 Beta ships with Gnome 49 and KDE Plasma 6.4 (and other goodies).
-
USB4 Maintainer Leaves Intel
Michael Jamet, one of the primary maintainers of USB4 and Thunderbolt drivers, has left Intel, leaving a gaping hole for the Linux community to deal with.
-
Budgie 10.9.3 Now Available
The latest version of this elegant and configurable Linux desktop aligns with changes in Gnome 49.
-
KDE Linux Alpha Available for Daring Users
It's official, KDE Linux has arrived, but it's not quite ready for prime time.
-
AMD Initiates Graphics Driver Updates for Linux Kernel 6.18
This new AMD update focuses on power management, display handling, and hardware support for Radeon GPUs.