Maker.io main logo

CircuitPython Sound Box

2018-05-01 | By Adafruit Industries

License: See Original Project 3D Printing

Courtesy of Adafruit

Guide by Ruiz Brothers

DIY Switches for Assistive Tech – Big Button Audio Sound Box

In this guide, you'll learn how to build an Audio Sound Box using Circuit Playground Express and CircuitPython. This device can play back short audio clips and features a really big arcade button that lights up when you press it. It’s a pretty simple project but it’s very useful for the assistive tech community. Similar products are actually quite pricey so a DIY solution can be cost-effective, and of course this is customizable!

 

 

Audio Sound Box

Prerequisite Guides

If you’re new to electronics and the Adafruit Circuit Playground Express, I suggest you walk through the following guides to get the basics. The Circuit Python guide will walk you through setting it up.

Electronic Components

Electronic Components

The Circuit Playground Express, massive arcade button, PAM8302 amplifier, and speaker are the main electronic components used in this project.

Hardware and Supplies

Just a few screws, stickers and wires.

  • 1 x JST Extension
  • 4 x M2.5 x .45 x 5mm
  • 2 x M3 x .45 x 5mm
  • 1 x 30AWG Wire
  • 1 x Solder Wire
  • 1 x Heat Shrink Tubing
  • 1 x Mounting Putty Tack

Cool Tools!

These help make the project a smooth building experience. You don't need them all of them, but I recommend them.

Circuit Diagram

Circuit Diagram

This provides a visual reference for wiring of the components. They aren't true to scale, just meant to be used as a reference.

  • VOUT from CPX to VIN on PAM8302
  • GND from CPX to GND on PAM8302
  • A0 from CPX to Pot
  • Pot to GND on CPX
  • Pot to A+ on PAM8302
  • from PAM8302 to GND on PAM8302
  • Button to GND on CPX
  • Button to A4 on CPX
  • Speaker to -+audio output on PAM8302
  • TRS to GND and A4 on CPX
  • Battery to Pot / JST Extension

Fritzing Diagram

Fritzing Diagram

The circuit diagram was assembled in the Fritzing software. All of the components are contained in the source so they can be reused to make new projects. Download and modify the circuit diagram.

bigmack.fzz

Software 

connect the board to your computer

Setup Adafruit Circuit Playground Express for CircuitPython

We'll need to get our board set up so we can run CircuitPython code. The 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 set up the firmware, once complete, come back here and proceed.

CircuitPython for Circuit Playground Express

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

Adafruit CircuitPython Bundle

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.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.

Create a new text document using a text app

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.

Installing Mu Editor

Copy Code
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_circuitplayground.express 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
# https://www.youtube.com/watch?v=exlRjDKHGRg
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
time.sleep(wait)

for i in range(len(pixels)):
pixels[i] = BLACK
time.sleep(wait)

while True:
if not button.value:

# uncomment this line if you want it to click!
# mouse.click(Mouse.LEFT_BUTTON

audio = audioio.AudioOut(board.SPEAKER, open(AUDIOFILE, "rb"))
audio.play()
while audio.playing:
simpleCircle(.05)
pass # wait for audio to finish
# wait for button to be released
while not button.value:
time.sleep(0.1)

Audio Files

If you'd like to create your own sounds, they will need to be a certain file format. Use audio software or online converters to encode your audio files. You can download our audio sample for reference and to quickly test and get started.

  • .Wav File format – 16-bit integer (Little Endian)
  • Mono, 22.050 kHz

electrons.wav

3D Printing

What If I Don't Have A 3D Printer?

Not to worry! You can use a 3D printing service such as 3DHubs or MakeXYZ to have a local 3D printer operator 3D print and ship your parts to you. This is a great way to get your parts 3D printed by local makers. You could also try checking out your local Library or search for a Maker Space.

3D Printed Parts

3D Printed Parts

All of the parts are 3D printed with FDM type 3D printers using various colored filaments. All of the parts are separated into pieces to make 3D printing easier. Assembly is pretty easy and straightforward. Use the links below to download the STLs files.

Download STLs from Thingiverse

Download STLs on Pinshape

Download STLs from Youmagine

Slice Settings

These parts have been tested and 3D printed on an Ultimaker 2+ and 3 using PLA filament. The parts were sliced using CURA 3.x with the following slice settings.

  • 220C extruder temp
  • 65c bed temp
  • 0.2 layer height
  • 0.38 line width
  • 2 Wall Line Count – 0.4 nozzle
  • 20% infill
  • 50mm/s print speed

Enclosure Design

To house all of the electronics I designed a parametric box using Autodesk Fusion 360. Most of the components will be paneled mounted or secured to built-in standoffs with machine screws.

Enclosure Design

Design Source Files

The camera body assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, SAT and more. Electronic components like the PAM8302, Circuit Playground Express, potentiometer, and speaker can be extracted from the Fusion 360 Archive.

Design Source Files

Download Fusion 360 Source

Button Assembly

Button Assembly

Disassembling Arcade Button

We'll need to take apart the arcade button in order to embed the CPX. The button is designed to be disassembled so it should be fairly straightforward. We'll start by removing the micro switch from the button assembly.

Remove Micro Switch

Grasp onto the outer button housing and micro switch. Firmly twist the micro switch counterclockwise – It should make a click. Then, pull out the body of the micro switch away from the stem. The micro switch should have the LED housing intact.

Remove Micro Switch

Remove Threaded Ring

Unscrew the threaded ring from the stem of the button housing. The outer button housing should loosely pull out from the stem.

Remove Threaded Ring

Separate Button Housing

Pinch the two white colored tips on the end of the button stem while pushing them into the stem – The white housing should lift up out of the black housing. Separate the two and set aside the compression spring.

Separate Button Housing

Spudger Action

Pry open the dome from the button housing using a spudger or tool with a slim shim edge to get in between the two. Firmly grasp onto the dome while conducting the prying action.

Spudger Action

Micro Switch Teardown

Pull back the taller black colored clip from the red side of the micro switch. Rotate the micro switch until it comes loose from the black colored housing. Pull out the LED housing and two metal terminals from the black housing.

Micro Switch Teardown

Pre-drill Planning

We need to pass wires through the white colored housing so we'll need to drill some holes. We can use the holes from the outer housing as a reference for marking where the holes need to be.

Pre-drill Planning

Marking Holes

Place the white colored button housing into the main container. Flip the assembly over and use a sharpie marker to fill the holes.

Marking Holes

Slotted Holes

Note the orientation of the legs on the white housing, this ought to be in the correct position to allow proper actuation. The two parts have some give so they can move slightly – you'll want to fill as much space available to create slotted holes.

Slotted Holes

Marked Holes

Remove the white housing from the container to the marked slotted holes. These don't have to be fully filled, just enough to get a good reference for drilling.

Marked Holes

Drill Holes

Now it's time to make drill holes! Your choice of tool, a rotary tool like a Dremel or an impact drill will suffice. To prevent drilling holes into our tabletop, we place a scrap piece of wood under the white housing. This will catch the drill bit when it pokes through the housing.

Drill Holes

Drilled Holes

Drilling plastic for too long can cause the material to overheat and melt leaving behind welded chips. I used a pointed sanding bit to grind away material while smoothing out the edges.

Drilled Holes

Test Fitting

Reinstall the housing to see if the holes line up – Be sure to orient the actuator legs in the correct positions. These holes should allow enough space for wires to pass through.

Test Fitting

USB Cable

Wire Lengths

We'll need access the USB port on the CPX once it is embedded inside the arcade button. So, we'll need to DIY a USB cable so that we can still connect the CPX. We'll need five wires to create a micro USB cable.

Wire Lengths

Wire Tinning

I suggest using 30AWG silicone coated wires. Different colored wires allow you to tell the connections apart from each other. Using wire stripper, remove a bit of insulation from each wire. To prevent the strands of wires from fraying, you can add a bit of solder to tin them.

Wire Tinning

Soldering Connector

We'll need to solder these wires to the male micro USB connector. Due to the tiny pads, this can be quite difficult – A pointy tipped soldering iron is recommended. Follow the circuit diagram to get the proper connections.

Soldering Connector

DIY USB Connector

Once soldered, I suggest adding pieces of heat shrink tubing to keep all of the wires bundled together. You'll want to double check your solder joints to ensure they're making proper connections.

DIY USB Connector

Amplifier

Wires for Audio Amplifier

The PAM8302 will need four wired connections. Three longer wires and one shorter wire. These wires will connect to the amplifier to the CPX. The potentiometer will be wired inline with the amp and CPX to allow volume adjustment.

Wires for Audio Amplifier

Tinning Wires

Using wire strippers, remove a bit of insulation from the tips of each wire. Then, tin the strands of wire together using a bit of solder. Third helping hands can help keep the wires in place while applying solder. Heat shrink tubing will help keep the wires together.

Tinning Wires

Amplifier Wires Soldered

Solder the wires to the pins on the PAM8302. The shorter wire should be wired to the A- labeled pin.

Amplifier Wires Soldered

Ground Audio Input

The wire connected to the A- pin will need to tie to the GND pin on the PAM8302. The GND pin should share two of the wired connections.

Ground Audio Input

Speaker

Connecting Speaker to Amp

The two wires from the speaker will need to be soldered to the audio output on the PAM8302 amplifier. I do not suggest using the included screw block terminal because it will block the mounting holes – Wires should be soldered directly to the pins.

Connecting Speaker to Amp

Speaker Audio Cable

The wire on the speaker is fairly long and can be shorted to keep the connections nice and neat. Use wire cutters to trim the cable short.

Speaker Audio Cable

Shortened Speaker Wire

The wire can be about the length of the 3D printed box enclosure.

Shortened Speaker Wire

Tinning Speaker Wires

Separate the speaker cable by pulling the two apart. Then, strip each wire using wire strippers. You can tin the exposed strands of wire by applying a bit of solder.

Tinning Speaker Wires

Solder Speaker Wires to Amp

The red colored wire is the (+)positive connection while the black is the (-)negative connection. Solder the two wires from the speaker to the output on the PAM8302.

Solder Speaker Wires to Amp

Pot Switch

Potentiometer and Switch Wires

The potentiometer will need two wires and the JST extension cable. This will need to be connected to both the battery and the PAM8302 audio amplifier.

Potentiometer and Switch Wires

Tin Wires

More wires mean more wire stripping and tinning! Using wire stripper, remove a bit of insulation from the tips of each wire and apply a bit of solder to tin the strands of wires. Adding a few pieces of heat shrink tubing will keep the wires bundled together.

Tin Wires

Solder Wires to Pot

The two wires can then be soldered to the two legs on the potentiometer. The blue wire is connected to the far left leg. The green wire is connected to the right left. Grab the PAM8302 audio amplifier and pick out the wire connected to the A+ pin. This wire needs to be soldered to the middle leg of the potentiometer.

Solder Wires to Pot

Remove nub

While we're working with the pot, remove the nub protruding from the top. This piece will prevent the pot from being panel mounted. I used flat pliers to grasp the nub and twisted it until it broke away.

Remove nub

Wired Potentiometer

Double check your wiring and ensure the wires are connected to the correct pins/terminals. Now is a good time to apply heat shrink tubing to keep the wires nice and tidy.

Wired Potentiometer

JST Extension

JST Extension Cable

We'll need to connect the JST extension cable to the on/off switch on the potentiometer. The cable features a male JST connector on one end and female on the other.

JST Extension Cable

Shortened Wires

You can shorten the wires using wire cutters. The end with the connectors are separated into two wires. The length of the wires is about the length of the wire cutters.

Shortened Wires

Tinned Wires

Using wire strippers, remove a bit of insulation from the tips of each wire. Then, add a bit of solder to tin the stranded of wire. Bits of heat shrink tubing will keep the wires bundled together when splitting them apart.

Tinned Wires

Tinning Switch Leads

On the bottom of the potentiometer are two extra legs – These are the terminals for the built-in switch. Apply a bit of solder to them to make it easier to attach the wires from the JST wires.

Tinning Switch Leads

Solder Wires to Switch

The red wires from the male and female JST wires need to be connected to the two terminals on the potentiometer switch. They should be wired in a "right-angled" orientation – This will make it nice and tidy once panel mounted to the 3D printed box enclosure.

Solder Wires to Switch

Tie Grounds

The black wires (ground connection) from the male and female JST wire needs to be connected together. Use a piece of heat shrink tubing to insulate the exposed wires.

Tie Grounds

Wired JST to Pot Switch

Double check all of the wired connections to ensure everything is properly soldered. Now is a good time to adjust wire lengths or add addition heat shrink tubing.

Wired JST to Pot Switch

Button

Disassemble Switch

I suggest taking the micro switch out of the housing. The assembly can be taken apart as shown in the photo. We won't be needing the LED, so you can discard it along with the electrode terminals. We will need the black housing bit, so keep that handy.

Disassemble Switch

Wires for Micro Switch

We need two wires to connect the micro switch to the CPX. The polarity doesn't matter for switches but I used different colored wires for consistency. Don't forget the heat shrink!

Wires for Micro Switch

Wire Tinning

More tinning here, you know the drill! Using wire strippers, remove a bit of insulation from the tips of each wire – Then apply a bit of solder to the strands of wire. Remember, third helping hands can help!

Wire Tinning

Tinning Terminals

OK, now it's time to wire up the micro switch. The terminals are rather chunky so you'll want to apply a good amount of solder to them. 

Tinning Terminals

Solder Wires to Terminals

Attach the wires! Again, polarity doesn't matter all that much but it’s good to keep the colors of the wires consistent with the rest of the connections.

Solder Wires to Terminals

Wired Micro Switch

Note the orientation of the wires. They're set up in a right-angle type position – This will accommodate for the space in the 3D printed box enclosure and keep a low-profile.

Wired Micro Switch

Reinstall Button Housing

Once wired, you can put the micro switch back into the black housing part.

Reinstall Button Housing

TRS Jack

Wires for the TRS jack

TRS audio jacks normally need three wired connections but we only need two for this project. Prep the wires by stripping a bit of insulation from the tips of each wire and apply a bit of solder to the strands to tin them.

Wires for the TRS jack

Jumper Jack

We'll need to tie the two smaller legs of the TRS jack together. So, I used a piece of header pins to do so. Each leg has a small hole in it, so I slipped on a single header pin to the holes, essentially bridging the two.

Jumper Jack

Tinning Terminals

Then, I apply some solder to fuse the header pin to the two legs. Be careful not to melt the plastic housing from the button or the header pin. You'll want to work quickly or the plastic will melt – Avoid holding the tip of the iron too long when soldering.

Tinning Terminals

Soldered Wires

Now we can attach the two wires to the larger leg and one of the smaller ones. Polarity doesn't matter as long as one wire is attached to one of the smaller legs, and the other to the larger leg.

Soldered Wires

Check Solder

You'll want to remove the plastic bit from the header pin and double check to ensure the solder joints are fully fused and making a solid electrical connection.

Check Solder

Wired TRS Jack

The TRS jack is now wired and ready to connect! Don't forget to add heat shrink!

Wired TRS Jack

Wired Components

Wired Components

Wiring Check Point

Now is a great time to double check all of the components to ensure everything is wired up correctly. If any wire lengths need to be adjusted or need additional pieces of heat shrink tubing, now is the time to get those set up.

Assembly

Install Button Holder

Fit the 3D printed button holder over the black button housing by inserting the steam through the center hole. The side walls should match up with the nubs on the side of the holder. Rotate the holder until they line up and hold them together.

Install Button Holder

Install Button to Box

Now fit the stem of the button housing through the center hole on the 3D printed box enclosure. Hold them together and flip the box under. Insert the threaded ring by screwing it onto the threaded stem of the button housing.

Install Button to Box

Setup Box

Ensure the holes are lined up before fully tightening the threaded ring.

Setup Box

Orient Holes

Flip the box assembly back over and look to see if the holes are all lined up and matching. If the holes are slightly off center, you can reinstall the button housing by rotating it 180 degrees.

Orient Holes

Install and Secure Speaker

Place the speaker into the 3D printed box enclosure. Orient the speaker so the cone lines up with the little holes on the side of the box. The tabs of the speaker should slide into the clips inside of the box. You can insert and fasten two M3 x 5mm screws to secure the top tabs on the speaker to the standoffs on the side of the box enclosure.

Install and Secure Speaker

Tap Mounting Holes

The mounting holes on the PAM8302 audio amplifier are a bit tight, so I suggest using an M2.5 tapping tool to thread the holes. This will make it easier to fasten M2.5 machine screws through the mounting holes.

Tap Mounting Holes

Secure Amplifier

Place the PAM8302 audio amplifier into the 3D printed box enclosure. Line up the mounting holes with the two standoffs inside the box. Hold the board down while fastening the machine screws to the standoffs.

Secure Amplifier

Install Potentiometer

Insert the shaft of the potentiometer through the inside of the 3D printed box enclosure. Press the shaft all the through the hole in the corner of the box. Hold it up against the top surface and insert the washer and hex nut. Fasten the nut until it's fully tightened and secured to the box.

Install Potentiometer

Thread Amp Wiring

Grab the wiring from the amplifier and thread them through one of the holes in the box. On the top side of the button, pull the wiring all the way through.

Thread Amp Wiring

Thread JST Power

Do the same wire thread for the JST male connector. I pushed the connector through a different hole.

Thread JST Power

Install TRS Jack

Insert the TRS jack through the side hole on the inside of the 3D printed box enclosure. While holding it in place, screw the included hex nut to panel mount the jack to the side of the box. Fasten the hex nut until it's fully tightened and secured to the box.

Install TRS Jack

Thread TRS Wires

Insert and thread the wiring from the TRS jack to one of the holes. Here I shared the same hole as the button wiring, for consistency purposes. They're both going to connect to the same pins on the CPX.

Thread TRS Wires

Installed TRS/Button Wires

Here's what the inside of the 3D printed box enclosure looks like. Try to keep the wires nice and tidy, so lots of heat shrink tubing is ideal.

Installed TRS / Button Wires

Installed USB Cable

Now we can insert the wires from the USB cable through the TOP of the button housing (not the inside). The male USB connector should be on the outside of the 3D printed box enclosure.

Installed USB Cable

Threaded Wiring

And now we have all of the wires threaded through the holes! Up next we'll connect all of these wires to the CPX.

Threaded Wiring

CPX Wiring

CPX Wiring Setup

OK, now it's time to wire up the CPX. Before we get started, its good idea to note which pads will be used. If you did use different colored wires for all of the components, it should be fairly easy to tell the connections apart from each other.

CPX Wiring Setup

Tinning Pads on CPX

To keep the wiring concealed and hidden, I ended up connecting the wired to the bottom of the board. However, it's a little more difficult because there are no labels on the bottom of the board. Either way, I tinned the pads with solder before attaching the wires.

Tinning Pads on CPX

Wired Connections

I soldered all of the wires oriented "inwards", again trying to keep the wiring nice and neat. The pads are quite large so it was possible to attach multiple wires to them – Like the TRS and micro switch connections, also one of the grounds.

Wired Connections

Plug In Power and USB

With the wires now soldered to the pads on the CPX, we can plug in the male JST connector and the male micro USB.

Plug In Power and USB

Final Wire Check

Here's the underbelly. Good idea to double check all of the wiring to ensure we soldered everything to the correct pads. If you connected to the bottom side, you may want to flip back and forth and cross-reference the circuit diagram.

Final Wire Check

Connect USB Breakout

And the last thing to wire up is the cable from the male micro USB connector. We saved this for last because we would not be able to thread either the USB connector nor the breakout board through the holes in the top.

Connect USB Breakout

Mount USB Breakout

With the breakout now wired up, we can mount it to the bottom cover of the 3D printed box enclosure. Place the board over the two standoffs with the USB port facing the edge. Use two M2.5 x 5mm machine screws to secure the board to the standoffs.

Mount USB Breakout

Connect Battery

Now we can plug in the battery to the female JST connector that resides inside the box. Here I'm using a hefty 2000mAh lipo cell but you can use a AA battery pack. Plenty of room inside the box the AA pack.

Connect Battery

Attach Battery

You'll need to attach the battery to the side walls of the 3D printed box enclosure. I used mounting tack but double-stick tape or hot glue will also work. Depends on if you want a more permanent solution or not. Either way, it’s no fun if the battery can jostle around in the box.

Attach Battery

Closing Bottom Cover

With everything secured, we can now snap on the bottom cover to the 3D printed box enclosure. Line up the bottom cover so the micro USB breakout is lined up with the small cutout on the side of the box.

Closing Bottom Cover

Closed Case

The little hole for the USB port should be large enough to allow even the chunkiest of microUSB cables because it's fairly close to the edge of the box.

Closed Case

Install Knob (Optional)

You can attach your own knob to the shaft of the potentiometer if you'd like. I opted in for that large machined knob to match the largeness of the arcade button. This knob has a set screw for securing to the shaft – You'll need an M2 sized Allen key to tighten the set screw.

Install Knob (Optional)

Test Cover

It's up to you whether or not you want to cover up the CPX board. I didn't at first but I found the included button cover diffuses the neopixel LEDs quite nicely.

Test Cover

Install Dome

Either way, you'll want to reinstall the dome back onto the top of the button housing. Firmly press down on the dome to snap the outer edges to the housing. It may require a good amount of force so don't fret if you think you're applying too much pressure.

Install Dome

制造商零件编号 3333
CIRCUIT PLAYGROUND EXPRESS
Adafruit Industries LLC
制造商零件编号 2130
EVAL BOARD FOR PAM8302A
Adafruit Industries LLC
制造商零件编号 2056
KNOB KNURLED 0.236" METAL
Adafruit Industries LLC
制造商零件编号 1390
CONN PLUG MICRO USB B 5POS SLDR
Adafruit Industries LLC
制造商零件编号 1833
USB MICRO-B BREAKOUT BOARD
Adafruit Industries LLC
制造商零件编号 3287
BATTERY HOLDER AA 3 CELL LEADS
Adafruit Industries LLC
制造商零件编号 1131
JST-PH BATTERY EXT CABLE
Adafruit Industries LLC
制造商零件编号 3434
STAINLESS STEEL SPUDGER - DOUBLE
Adafruit Industries LLC
制造商零件编号 1192
SWITCH PUSHBUTTON SPST-NO WHT
Adafruit Industries LLC
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum