Getting Familiar

CircuitPython is a programming language based on Python, one of the fastest growing programming languages in the world. It is specifically designed to simplify experimenting and learning to code on low-cost microcontroller boards.

CircuitPython is easiest to use within the Mu Editor. If you haven't previously used Mu, this guide will get you started.

If you haven't used Circuit Playground Express and CircuitPython together before, make sure you've updated it with the latest version of CircuitPython. This guide will show you how.

The Code

Plug your Circuit Playground Express into your computer (mac/PC/Linux) via a known good USB A to micro-B cable. Your board should appear to the computer as a flash disk drive named CIRCUITPY. If you see a disk name CPLAYBOOT, try to press the reset button again. If the only drive name you get is CPLAYBOOT, CircuitPython may not be loaded on the board. You can load CircuitPython per this guide.

Copy code.py from the link below and put it in CIRCUITPY root directory. You can work with this code in any text editing application, or open and save with Mu if you prefer. You will need to ensure the wav file you have prepared is coded into the code, i.e. if your wav file is trumpet.wav, then in the code replace imperial_march.wav with trumpet.wav.

# Talking Cane
# for Adafruit Circuit Playground Express with CircuitPython
from adafruit_circuitplayground.express import cpx

# Change this number to adjust touch sensitivity threshold
cpx.adjust_touch_threshold(600)
# Set the tap type: 1=single, 2=double
cpx.detect_taps = 1

# NeoPixel colors used
RED = (90, 0, 0)
BLACK = (0, 0, 0)

cpx.pixels.brightness = 0.1  # set brightness value

# The audio file assigned to the touchpad
audio_file = "imperial_march.wav"

def play_it():
    cpx.pixels.fill(RED)  # Light neopixels
    cpx.play_file(audio_file)  # play audio clip
    print("playing file ", audio_file)
    cpx.pixels.fill(BLACK)  # unlight lights

while True:
    # playback mode. Use the slide switch to change between
    #   trigger via touch or via single tap
    if cpx.switch:
        if cpx.touch_A1:
            play_it()
    else:
        if cpx.tapped:
            play_it()

No libraries are need for this code to run, just drag and drop your WAV file of choice onto your CIRCUITPY drive.

Once the code is saved to CIRCUITPY and your audio file is on there too, you should be able to test that it plays by touching the capacitive pad or shaking the board and the miniature speaker on the STEMMA board will play your chosen audio.

Change Functions

By changing the position of the slide switch on the board, you can alter the function, making it sensitive to impacts instead of touch sensitive.

The code is set up so that it's easy to add multiple audio files to the project, which can play in random order or be tied to specific inputs from Circuit Playground Express.

Troubleshooting

Problem: My Circuit Playground Express isn't recognized by Mu!

Solution: Make sure your board is set up with CircuitPython, which has the Circuit Playground Express show up as a flash drive named CIRCUITPY when you connect the CPX to your computer. If it is showing up as CPLAYBOOT on your computer, you can follow the steps in this guide to ensure CircuitPython is loaded and you see the CIRCUITPY drive.

 

Problem: I can't hear any audio!

Solution: Check that your audio file name matches what is written in the code. 

 

Problem: I STILL can't hear any audio!

Solution: If you're using a battery pack, check that your Circuit Playground Express is connected and the slide switch on the pack is set to "ON".

This guide was first published on Nov 13, 2019. It was last updated on Nov 13, 2019.

This page (CircuitPython Code) was last updated on Oct 15, 2021.

Text editor powered by tinymce.