In the previous 3D Printed Doctor Who Tardis make I complained that the sound was poor quality and low volume. This was a natural outcome of pushing the little AVR ATMega128 to the limit. Really if you want to play MP3 audio then you need MP3 hardware. I tried an Adafruit module. It was great, but expensive. We don’t really want to have an SD card in there either because they are prone to knocks and corruption. What we want is a solid state MP3 player, without breaking the bank. Does such a unicorn exist? You bet!
Cheap, Loud, Easy and Sounds Good??
After Maker Faire I hunted around for some solutions and there were a few, from expensive Arduino “WAV” shields through to buying off the shelf gadgets and taking them apart. For the volume issue I bought an amplifier and learned how to make the circuits, but the audio quality remained, with the budget caveat. Not easy.
Don’t get me wrong, the PCM sound is fine for the occasional squeaky audio feedback and the Dalek sounds are not known for their audio fidelity, but in the midst of Maker Faire buzz, I found most people didn’t realize the Tardis made sounds at all, plus the theme doesn’t sound great when super compressed to fit into the ATMega’s tiny memory. SD cards are wasteful too when the maximum capacity I need means only filling a corner of the card, without even thinking about how often they corrupt or dislodge when knocked around and rebooted as often as something handled at a comic or gadget fair will be. The Adafruit module is excellent, and fully justifiable if making a commissioned piece, but for a silly gizmo I like to keep costs down.
In the end I happened across this guy.
There are various variations of it, but I went for an 8mb version (64Mbit) because I knew I needed to play theme tunes etc as well as short effects. I bought 4 for $30 CAD, so around $5-$6 USD. Considering I bought the higher memory version and it doesn’t require an SD card that’s pretty inexpensive. So cheap = check!
Was it easy? I would say so.
It’s actually a self-contained unit. Just connect any of the play pins to ground and you can play one of 10 sounds without the need for the Arduino, so you can be up and running in minutes. Plug it in to your computer via the USB port and load up the sound files as if it is an external drive, then rename the files in numerical order, 001.mp3 etc.
In my case I wanted to control the module programmatically, so I hooked mine up to the Arduino.
Now had I been using, say, an Arduino Mega, I don’t have to worry about running out of pins, but in my case I wanted to use a Nano or Pro Mini, and ideally I wanted to fill that 8mb of space up. That meant I needed to find out how to play more than 10 sounds and how to do it without using the pins. All the documentation I found was chinese. Yay.
Turns out someone called “Critters” had written a lovely little github repo with everything we need, including an Arduino library!
Playing a Random Sound Along with Tardis Light Effect
Here is the code, with MP3 playing and light fading effect:
RX/TX are on pins 10,11. Connect Busy to A0. Power and ground are obvious. I used an RGB LED so that I could, say, glow red when it is a Dalek sound, but for this simple demo I am just using the Blue pin.
You will notice for the fade we use Millis. This is so we can get the Arduino doing other multitasking kind of stuff, as checking Millis does not make the whole thing wait for the delay. It’s all very simple, I just randomly pick an MP3 and play it so long as nothing is already playing.
Here it is in action: