It's easy to use the Pixel Trinkey with CircuitPython and the Adafruit_CircuitPython_NeoPixel module. This module allows you to easily write Python code that lets you control NeoPixels.
Connect your NeoPixels to the terminal block on the Pixel Trinkey:
- Board GND to NeoPixel GND (black wire)
- Board DATA to NeoPixel DATA IN (blue wire)
- Board +5V to NeoPixel VIN (red wire)
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: 2024 Liz Clark for Adafruit Industries # SPDX-License-Identifier: MIT import time import board from rainbowio import colorwheel import neopixel pixel_pin = board.DATA num_pixels = 30 speed = 0.01 brightness = 0.5 order = "GRB" # "GRBW" for RGBW NeoPixels pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=brightness, auto_write=True, pixel_order=order) hue = 0 pixels.fill(colorwheel(hue)) while True: hue = (hue + 1) % 256 pixels.fill(colorwheel(hue)) time.sleep(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 pixel order depending on your needs.
pixel_pin = board.DATA num_pixels = 30 speed = 0.01 brightness = 0.5 order = "GRB" # "GRBW" for RGBW NeoPixels
Text editor powered by tinymce.