FAQ: Circuit Playground: Part 2 - Review

This community-built FAQ covers the “Review” exercise from the lesson “Circuit Playground: Part 2”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Hardware Programming with CircuitPython

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I went through the 808 drum kit exercise and it doesn’t appear to be working. Do you know what’s wrong with my code? I also don’t have an external speaker to use, how can I use the on board speaker? Also, how would I connect an alligator clip to an external speaker?

Here’s my code:

import audioio
import touchio
import board
import time

from digitalio import DigitalInOut, Direction

bpm = 120 # beats per minute

Enable the speaker

spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = Direction.OUTPUT
spkrenable.value = True

Make the input cap sense pads

capPins = (board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.A7)

touchPad =

for i in range(7):
touchPad.append(touchio.TouchIn(capPins[i]))

The seven audio files

audiofiles = [“bd_tek.wav”, “elec_hi_snare.wav”, “elec_cymbal.wav”, “elec_blip2.wav”, “bd_zome.wav”, “bass_hit_c.wav”, “drum_cowbell.wav”]

Audio Out

a = audioio.AudioOut(board.A0)

Play File Function

def play_file(filename):
f = open(filename, “rb”)
wave = audioio.WaveFile(f)
a.play(wave)
time.sleep(bpm/960) # sixteenthNote delay

Infinite Loop

while True:
for i in range(7):
if touchPad[i].value:
play_file(audiofiles[i])

I found this code on the Adafruit site and it works fine. Can also use it to connect to an external speaker without changing any of the code. Also added a touch pad threshold because the default raw value was way too sensitive and the files just played constantly, even when I just hovered my finger over the board or a piece of fruit. It seems to change sensitivity based on being connected to USB or battery, adjust for whatever works for you.

I did use different audio files that had to be converted to be compatible with the board. See the Adafruit website on how to convert audio files.

Circuit Playground 808 Drum machine

import time
import board
import touchio
import digitalio

try:
from audiocore import WaveFile
except ImportError:
from audioio import WaveFile

try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!

bpm = 120
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
speaker_enable.direction = digitalio.Direction.OUTPUT
speaker_enable.value = True

capPins = (board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.TX)

touchPad =
for i in range(7):
touchPad.append(touchio.TouchIn(capPins[i]))
# Touch Threshold #
# For USB
#touchPad[i].threshold += 1000
# For Battery
touchPad[i].threshold += 600

audiofiles = [
“kick.wav”,
“snare.wav”,
“chim.wav”,
“hihat2.wav”,
“tom.wav”,
“s3him.wav”,
“hihat.wav”,
]

audio = AudioOut(board.SPEAKER)

def play_file(filename):
print("playing file " + filename)
file = open(filename, “rb”)
wave = WaveFile(file)
audio.play(wave)
time.sleep(bpm / 960)

while True:
for i in range(7):
if touchPad[i].value:
play_file(audiofiles[i])