It's easy to use the Pixie LEDs with CircuitPython and Python via the Adafruit CircuitPython Pixie module. You can light up each LED differently, light them all up the same, or even light up a rainbow!
You can use the pixels with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
CircuitPython Microcontroller Wiring
First wire up the Pixie LEDs as shown in Assembly.
Pixie LEDs use UART (serial) to communicate. They only receive data. So you're only connecting two wires to your microcontroller board.
Here is an example with a Feather M0 Express:
- Feather TX to Pixie data in
- Feather Gnd to Pixie shared ground
Pixies require an external power source and sufficient gauge power wire! Follow the previous pages in this guide to ensure you have wired them properly.
Python Computer Wiring
Since there's dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired with UART:
- Pi TX to Pixie data in
- Pi Gnd to Pixie shared ground
Pixies require an external power source and sufficient gauge power wire! Follow the previous pages in this guide to ensure you have wired them properly.
Here's the Pixie LEDs wired up to a USB to serial converter:
- USB serial TX to Pixie data in
- USB serial ground to Pixie shared ground
Pixies require an external power source and sufficient gauge power wire! Follow the previous pages in this guide to ensure you have wired them properly.
CircuitPython Installation of Pixie Library
You'll need to install the Adafruit CircuitPython Pixie library on your CircuitPython board.
First make sure you are running the latest version of Adafruit CircuitPython for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle. Our CircuitPython starter guide has a great page on how to install the library bundle.
Copy the necessary libraries from the bundle to the lib folder on your CIRCUITPY drive:
- adafruit_pixie.mpy
- adafruit_bus_device
Before continuing, make sure your board's lib folder has the adafruit_pixie.mpy and adafruit_bus_device files and folders copied over
Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt.
Single Board Computer Python Installation of the Pixie Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-pixie
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython & Python Usage
To demonstrate usage, we'll initialise the LEDs and then change the color, brightness and more using the board's Python REPL.
For CircuitPython, run the following code to import the necessary modules and initialise the UART object:
import board import adafruit_pixie import busio uart = busio.UART(board.TX, rx=None, baudrate=115200)
For use with Linux and Python, ensure you have UART properly enabled on your computer. This guide shows how to do this on Raspberry Pi. Once enabled, run the following code to import the necessary modules and initialise the UART object:
import time import adafruit_pixie import serial uart = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=3000)
Run the following to set the number of Pixies to 2
, and initialise the pixies
object. If you have more or less than two Pixies connected, change num_pixies
to match. Note that we set the brightness to 0.2 - Pixie LEDs are super bright! Even at 20% brightness, you may want to point them away from you or place a diffuser over them.
num_pixies = 2 # Change this to the number of Pixie LEDs you have. pixies = adafruit_pixie.Pixie(uart, num_pixies, brightness=0.2)
Now you're ready to change your LEDs using any of the following:
- fill - Color all Pixies a given color.
- brightness - Change the brightness of the LEDs by setting to a number between 0 and 1 representing a percentage from 0 to 100%.
-
show - Update the LED colors if
auto_write
is set toFalse
.
pixies[0] = (0, 255, 0) pixies[0] = (0, 0, 0) pixies[1] = (0, 0, 255) pixies[1] = (0, 0, 0) pixies.fill((255, 0, 0)) pixies.fill((0, 0, 0))
This code lights up the first Pixie LED blue and turns it off, then lights up the second one green and turns it off. Then it lights up all the Pixie LEDs red, and then turns all of them off.
That's all there is to using Pixie LEDs with CircuitPython! You can add more Pixies to your string, create rainbow animations and more. Check out the example below!
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT import time import board import busio from rainbowio import colorwheel import adafruit_pixie # For use with CircuitPython: uart = busio.UART(board.TX, rx=None, baudrate=115200) # For use on Raspberry Pi/Linux with Adafruit_Blinka: # import serial # uart = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=3000) num_pixies = 2 # Change this to the number of Pixie LEDs you have. pixies = adafruit_pixie.Pixie(uart, num_pixies, brightness=0.2, auto_write=False) while True: for i in range(255): for pixie in range(num_pixies): pixies[pixie] = colorwheel(i) pixies.show() time.sleep(2) pixies[0] = (0, 255, 0) pixies[1] = (0, 0, 255) pixies.show() time.sleep(1) pixies.fill((255, 0, 0)) pixies.show() time.sleep(1) pixies[::2] = [(255, 0, 100)] * (2 // 2) pixies[1::2] = [(0, 255, 255)] * (2 // 2) pixies.show() time.sleep(1)
Text editor powered by tinymce.