Setup Adafruit Circuit Playground Express for CircuitPython

We'll need to get our board setup so we can run CircuitPython code. First thing we'll need to do is connect the board to your computer with a microUSB cable. Then double-click on the reset button to put it in "UF2" boot-loader mode. The NeoPixels will turn green. The board will then show up as a USB storage device on your computer named "CPLAYBOOT". 

Follow the guide below to setup the firmware, once complete, come back here and proceed.

Download Adafruit CircuitPython Library Bundle

In order to run the code, we'll need to download some libraries. The download linked below will contain all the libraries available for Circuit Python. To run the code for this project, we only need a few. Unzip the downloaded file and look for the following libraries.

Required Libraries 

  • Adafruit Neopixel – neopixel.mpy
  • Adafruit HID – adafruit_hid
  • Adafruit Circuit Playground – adafruit_circuitplayground

Install Circuit Python Libraries 

Now that we have all of the libraries and know which ones this project needs, we'll need to copy them onto the Circuit Playground Express USB drive (which will be named CIRCUITPY after flashing the firmware). In the CIRCUITPY drive, create a new folder and name it "lib". Then, copy the libraries to that "lib" folder. The lib folder should contain neopixel.mpyadafruit_hid and adafruit_circuitplayground .

Upload Code

OK, now it's time to upload the code for this project onto the CIRCUITPY drive. Create a new text document using a text app. Then, copy the code below and paste it into that newly created text document. Save that text document to the CIRCUITPY drive and name it "". Once saved, the code will automatically run and will start working.

Editing Code

You'll want to use the Mu python editor to modify the code. Mu is a simple code editor that works with the Adafruit CircuitPython boards. It's written in Python and works on Windows, MacOS, Linux and Raspberry Pi. The serial console is built right in so you get immediate feedback from your board's serial output! See the guide below to for download and setup instructions.

Download: file
import board
from digitalio import DigitalInOut, Direction, Pull
from import cpx
import audioio
from adafruit_hid.mouse import Mouse
import neopixel
import time

# Audio file name
# By default we'll use a friendly sample of Adabot
AUDIOFILE = "electrons.wav"

# What pad our button is connected to:
button = DigitalInOut(board.A4)
button.direction = Direction.INPUT
button.pull = Pull.UP

# From 0 to 1.0 - adjust as desired!
cpx.pixels.brightness = 0.5

# also be a 'mouse' if desired (requires being plugged into the tablet/computer)
mouse = Mouse()

#NeoPixel stuff
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)

def simpleCircle(wait):
    PURPLE = (0x10, 0, 0x10)
    BLACK = (0, 0, 0)

    for i in range(len(pixels)):
        pixels[i] = PURPLE

    for i in range(len(pixels)):
        pixels[i] = BLACK

while True:
    if not button.value:
        # uncomment this line if you want it to click!
        audio = audioio.AudioOut(board.SPEAKER, open(AUDIOFILE, "rb"))
        while audio.playing:
            pass   # wait for audio to finish
        # wait for button to be released
        while not button.value:

Audio Files

If you'd like to create your own sounds, they will need to be a certain file format. You can use this Adafruit Guide or online converters to encode your audio files. You can download our audio sample for reference and to quickly test and get started. The format of the sound file should be:

  • .Wav File format – 16-bit integer (Little Endian)
  • Mono, 22.050 kHz
This guide was first published on Feb 14, 2018. It was last updated on Feb 14, 2018. This page (Software) was last updated on Dec 18, 2018.