Once your Feather is set up with CircuitPython 5.3.0 or greater, you'll also need to add some libraries. Follow this page for information on how to download and add libraries to your Feather.

From the library bundle you downloaded in that guide page, transfer the following libraries onto the Feather's /lib directory:

  • adafruit_bus_device
  • adafruit_lis3dh
  • neopixel

Text Editor

Adafruit recommends using the Mu editor for using your CircuitPython code with the Feather boards. You can get more info in this guide.

Alternatively, you can use any text editor that saves files.


Copy the code below and paste it into Mu. Then, save it to your Feather as code.py.

# MP3 playback with tap trigger
# Works on Feather M4 (or other M4 based boards) with Propmaker
import time
import board
import busio
import digitalio
import audioio
import audiomp3
import adafruit_lis3dh

startup_play = False  # set to True to play all samples once on startup

# Set up accelerometer on I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
int1 = digitalio.DigitalInOut(board.D6)
accel = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
accel.set_tap(1, 100)  # single or double-tap, threshold

# Set up speaker enable pin
enable = digitalio.DigitalInOut(board.D10)
enable.direction = digitalio.Direction.OUTPUT
enable.value = True

speaker = audioio.AudioOut(board.A0)

sample_number = 0

print("Lars says, 'Hello, CVT Joseph. Tap to play.'")

if startup_play:  # Play all on startup
    for i in range(10):
        sample = "/lars/lars_0{}.mp3".format(i)
        print("Now playing: '{}'".format(sample))
        mp3stream = audiomp3.MP3Decoder(open(sample, "rb"))

        while speaker.playing:
    enable.value = speaker.playing

while True:
    if accel.tapped and speaker.playing is False:
        sample = "/lars/lars_0{}.mp3".format(sample_number)
        print("Now playing: '{}'".format(sample))
        mp3stream = audiomp3.MP3Decoder(open(sample, "rb"))
        sample_number = (sample_number + 1) % 10
    enable.value = speaker.playing

Audio Samples

You can get started by using these .mp3 files. (Of course, you're free to use any files that you like, see below for more info on that.)

Download the .zip file linked below and then uncompress the file. Drag the /lars directory onto the root level of your Feather's CIRCUITPY drive.

Make Your Own

To make your own .mp3, use audio software such as Audacity to save them with these settings:

  • bit rate: anywhere from 16 to 320 kb/s (lower will be smaller, higher is better quality)
  • sample rate: 22050Hz or 44100Hz are recommended, although 16kHz, 24kHz, and 48kHz should also work
  • channels: mono or stereo
  • must be DRM free

How It Works

Here's what the code does:

  • Imports the necessary libraries for audiomp3 playback and accelerometer tap detection with the adafruit_lis3dh
  • Sets up the accelerometer
  • Specifies the speaker enable pin (this allows the speaker to be disabled when not in use)
  • If startup_play is set to True, each sample in the /lars directory with the name format of /lars_0*.mp3 will be played using the mp3stream object
  • In the main loop of the program, the accelerometer is checked for tap detection. When the tap occurs, the next sample is played. When the tenth one is played, the list loops around back to the first one again.

Test It

With the enable switch clicked on, try tapping the Feather/Propmaker to trigger a sample. When a sample has finished you can tap again to trigger the next one.

Note, there is a small volume adjustment screw on the Propmaker FeatherWing that can be turned with a small screwdriver to adjust the maximum volume.

Now, let's add the sound player to our puppet friend Lars!

This guide was first published on May 27, 2020. It was last updated on May 27, 2020.

This page (Code the MP3 Player) was last updated on Apr 15, 2021.

Text editor powered by tinymce.