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
-
Fedora 43 Has Finally Landed
The Fedora Linux developers have announced their latest release, Fedora 43.
-
KDE Unleashes Plasma 6.5
The Plasma 6.5 desktop environment is now available with new features, improvements, and the usual bug fixes.
-
Xubuntu Site Possibly Hacked
It appears that the Xubuntu site was hacked and briefly served up a malicious ZIP file from its download page.
-
LMDE 7 Now Available
Linux Mint Debian Edition, version 7, has been officially released and is based on upstream Debian.
-
Linux Kernel 6.16 Reaches EOL
Linux kernel 6.16 has reached its end of life, which means you'll need to upgrade to the next stable release, Linux kernel 6.17.
-
Amazon Ditches Android for a Linux-Based OS
Amazon has migrated from Android to the Linux-based Vega OS for its Fire TV.
-
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.

