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
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 CircuitPlayground 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.mpy, adafruit_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 "main.py". 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.
# SPDX-FileCopyrightText: 2019 Noe Ruiz for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board from digitalio import DigitalInOut, Direction, Pull import audioio import audiocore import neopixel filename = "electrons.wav" # The pad our button is connected to: button = DigitalInOut(board.A4) button.direction = Direction.INPUT button.pull = Pull.UP pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1) # NeoPixel Animation def simpleCircle(wait): PURPLE = (255, 0, 255) BLACK = (0, 0, 0) CYAN = (0, 255, 255) ORANGE = (255, 255, 0) for i in range(len(pixels)): pixels[i] = PURPLE time.sleep(wait) for i in range(len(pixels)): pixels[i] = CYAN time.sleep(wait) for i in range(len(pixels)): pixels[i] = ORANGE time.sleep(wait) for i in range(len(pixels)): pixels[i] = BLACK time.sleep(wait) # Audio Play File def play_file(playname): print("Playing File " + playname) wave_file = open(playname, "rb") with audiocore.WaveFile(wave_file) as wave: with audioio.AudioOut(board.A0) as audio: audio.play(wave) while audio.playing: simpleCircle(.02) print("finished") while True: if not button.value: play_file(filename)
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
Text editor powered by tinymce.