It's easy to use the NeoPixel Driver BFF with CircuitPython and the Adafruit_CircuitPython_NeoPixel module. This module allows you to easily write Python code that lets you control NeoPixels.
CircuitPython Microcontroller Wiring
First, wire up a NeoPixel Driver BFF to your board exactly as shown below. Here's an example of wiring a QT Py RP2040 to the BFF with a strip of NeoPixels with a JST PH plug:
Connect the QT Py RP2040 with plug headers into the NeoPixel Driver BFF with socket headers. They should be plugged in with the backs of the boards facing each other.
For more information on soldering socket headers, check out this Learn Guide.
CircuitPython Usage
To use with CircuitPython, you need to first install the NeoPixel library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following files:
- adafruit_pixelbuf.mpy
- neopixel.mpy
# SPDX-FileCopyrightText: 2022 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT import time import board from rainbowio import colorwheel import neopixel NUMPIXELS = 12 # Update this to match the number of LEDs. SPEED = 0.05 # Increase to slow down the rainbow. Decrease to speed it up. BRIGHTNESS = 0.2 # A number between 0.0 and 1.0, where 0.0 is off, and 1.0 is max. PIN = board.A3 # This is the default pin on the 5x5 NeoPixel Grid BFF. pixels = neopixel.NeoPixel(PIN, NUMPIXELS, brightness=BRIGHTNESS, auto_write=False) def rainbow_cycle(wait): for color in range(255): for pixel in range(len(pixels)): # pylint: disable=consider-using-enumerate pixel_index = (pixel * 256 // len(pixels)) + color * 5 pixels[pixel] = colorwheel(pixel_index & 255) pixels.show() time.sleep(wait) while True: rainbow_cycle(SPEED)
Once everything is saved to the CIRCUITPY drive, you'll see your connected NeoPixel strip cycle through a rainbow animation on a loop.
You can edit the variables in the code for the number of pixels, speed, brightness and pin number depending on your needs.
NUMPIXELS = 12 # Update this to match the number of LEDs. SPEED = 0.05 # Increase to slow down the rainbow. Decrease to speed it up. BRIGHTNESS = 0.2 # A number between 0.0 and 1.0, where 0.0 is off, and 1.0 is max. PIN = board.A3 # This is the default pin on the 5x5 NeoPixel Grid BFF. pixels = neopixel.NeoPixel(PIN, NUMPIXELS, brightness=BRIGHTNESS, auto_write=False)
Text editor powered by tinymce.