There are plenty of ways to play sound on an Arduino– at the most basic you might burp out some bleeps and bloops with the tone() command, or perhaps drop some coin at Adafruit and get yourself a multifunction music shield.
Our current passion project at Zheng Labs is an audio-enabling upgrade to Plutarch the Pirate Parrot. For this application neither of the above options will quite fit the bill. We want a board that’s inexpensive, light, and small enough to fit inside a roaster chicken’s body cavity while leaving room for a battery pack, microcontroller, and an ever-increasing number of servos.
Enter The WTV020SD-16P. ‘Tis a picky, tricksy little board, but once you get it up and running it’s scrum-diddly-fun to use.
To the tutorial!
GATHER YOUR PARTS
- a WTV020SD-16P
- a SanDisk 1GB MicroSD card: apparently the WTV020SD-16P can be a little picky about which brand and capacity of MicroSD card will work.
- a speaker: This one comes with micro-JST connectors, which you can just snip off and plug into your breadboard. I soldered some jumper wires onto mine to make working with the breadboard easier.
some jumper wires
GET THE SOFTWARE
You can get the sample code and the software library you’ll need at the Arduino forum.
Oh God. Forums.
I can’t be the only one who dreads wading into technical forums seeking assistance. In my experience one can find tiny nuggets of precious content only by softing through the dross, dregs and slag of misinformation, know-it-all-ism, and half-baked do-my-homework-for-me questions IN ALL CAPS from engineering undergrads in Gdansk.
Every now and then a patient, knowledgable member with a willingness to shepherd a n00b through a confusing and contradictory information maelstrom will emerge, but more likely than not a cheeto-crusted basement dweller will snidely inform you that a B+ in Electrical Engineering 101 at Carnegie Mellon is a prerequisite for posing a question to your betters.
Thankfully, the Arduino forum’s friendlier than most, and it’s a decent place to start looking for information about the WTV020SD-16P. There’s still a lot to unpack and sort out before you get your board talking, though.
Once you’ve gotten the sample code from the forum you’ll no doubt come across this image in all its JPEG-compressed glory. It’s the second post on the forum. You can’t miss it.
I can’t stress this enough: do not use this image as your Virgil to guide you through this particular circle of Arduino Hell. There’s nothing inaccurate about it, but there’s too much information here for those who want to just plug this thing into an Arduino without having to first procure an EE degree, and some of it is misleading.
This schematic will get you a WTV020SD-16P that works in standalone mode with some pushbuttons, to be sure, but if all you want to do is control the board with Arduino code this wiring diagram is overkill. For one, the pins in this schematic don’t match the pins specified in the sample code right above it, which is one of those Things You Don’t Know You Don’t Know if you’re just starting out.
My edited schematic is a little simpler and balls-on accurate, I promise. Behold!
You’ll note that the sample code includes a declaration for a Busy pin. It’s used for asynchronous audio play but we’re keeping things simple and not using it in this tutorial. Also, you’ll see several pins on the WTV020SD-16P labeled as NC: they’re Not Connected to anything and can be safely ignored.
If reading schematics ain’t yo thang, here’s what it looks like IRL:
- Arduino 3V3 to pin 16 (top right of the board)
- Arduino pin 2 to pin 1
- Arduino pin 3 to pin 7
- Arduino pin 4 to pin 10
- Speaker + to pin 4 (usually this is the red wire)
- Speaker – to pin 5 (usually the black wire)
- Arduino GND to pin 8
You can download the commonly used sample .ad4 files here, or use mine which IMHO are better for diagnostics and have the added benefit of not dancing on the knife’s edge of fair use and international copyright law violation.
Unzip the archive and drop the files into the root directory of your FAT16-formatted MicroSD card. Files must be named 0000.ad4, 0001.ad4, 0002.ad4, etc. The WTV020SD-16P supports up to 512 audio files, which should be enough for all but the most loquacious of parrot puppets.
Be sure to have your source audio sampling rate set at 32kHz or the software won’t produce any output and (not helpfully) any error messages indicating that there’s a problem.
On OSX, drag the library folder into ~/Documents/Arduino/libraries/
The sample code on the forum shows off everything the library can do, but it’s too much for a proof of concept and has some English errors that introduce ambiguity in the comments. Let’s do some minor surgery.
- Cut out everything in between the curly brackets of the loop() function.
- Paste the following between the now-empty curly brackets after loop():
Power up your Arduino, upload the new code and you should be good to go. Good luck, and please post in the comments if I screwed anything up in the tutorial.
Watch this space for news on Plutarch 2.0’s evolution over the next few months. He’s scheduled to debut on Halloween 2017. You might consider watching his progress on Instagram or Twitter: that’s where the microupdates get posted first.
Lao Zheng out.