Let's light up some NeoPixels!

We could use the SPI port to do this, using the hack provided by the neopixel_spi library. But the u2if firmware supports the real deal. No need for the hack. Just wire NeoPixels to any available GP pin and use the normal neopixel library.

Here's an example wiring:

This example uses a 12 ring RGB NeoPixel. For any other setup, just change the number of pixels and possibly the pixel order.

Currently, only RGB NeoPixels are supported.
While NeoPixels are best used with 5V power and 5V logic, many times they are fine with 3.3V logic. If you don't get the LEDs to light up, try powering the ring from 3.3V or adding a level shifter

Install NeoPixel Library

To install the NeoPixel library, run the following:

sudo pip3 install adafruit-circuitpython-neopixel

These are the same install instructions as found in the main NeoPixel guide.

Run Example

And here is the example code to drive the 12 NeoPixel ring. To keep things simple, we simply fill the ring with various colors.

import time
import board
import neopixel

COLORS = (
    (255,   0,   0),
    (  0, 255,   0),
    (  0,   0, 255),
    (255, 255,   0),
    (255,   0, 255),
    (  0, 255, 255),
)

pixels = neopixel.NeoPixel(board.GP28, 12)

while True:
    for color in COLORS:
        pixels.fill(color)
        time.sleep(1)

Save that as something like neopixel_ring.py and then run with the following:

python3 neopixel_ring.py

And the ring should light up!

This guide was first published on May 01, 2021. It was last updated on 2021-05-26 15:05:43 -0400.

This page (NeoPixel) was last updated on Nov 27, 2021.

Text editor powered by tinymce.