She found an appropriate looking toy music player at a thrift store, it even had a CD-looking spinny bit that would go around when you moved a slider. Then she handed it off to me, asking if I could make it play custom music. Dragon*Con wasn't far off, so there wasn't much time. I said I'd have a look.
Back at the lab, I opened it up for a look-see.
Not much to it, really. Battery holder, speaker, a small circuit board, and some LEDs.
Further diassembly revealed the details of the circuit board.
It's pretty cheap construction. There's a black epoxy blob covering the brains of it. the circuit board has traces that form the contacts for the four pushbuttons, and the power switch. Also, the four pushbuttons are all connected together, the thing has no way of knowing which one was pressed, it just does one of it's canned tunes when any button is pressed.
I decided to keep the circuit board, since it was part of the switches, and that was a lot easier than finding a way to make other switches fit properly. Some cutting of traces allowed me to isolate the switches, so I could have four different functions, instead of one function activated by any one of the four buttons. I also disconnected the original electronics, which were not going to be needed any more.
But what to replace them with? At first, I thought I'd try fizzygeek's old Pulse player, a cheap early MP3 player that neither one of us had a need for any more.
I could connect the switches to its controls, maybe find a way to amplify its output to drive the speaker, and load it up with appropriate music. Unfortunately, its controls were the generic "play", "skip", "pause" sorts of things, and werewulf wanted the modified unit to play particular tracks when the buttons were pressed. I considered adding a CPU to translate the button presses to MP3 player commands, but it seemed like things could lose sync pretty easily, and if I was going to put in my own CPU anyway, may as well let it do all the work.
The trickiest part would be playing custom tunes, so I started with that. I chose the Adafruit Wave Shield, which is a very capable little board, which allows reading tunes off an SD card and playing them back under computer control. It also includes an amplifer (a TL072 doesn't push much power into a speaker, but it would have to be enough), volume control, and even a headphone jack. I also ordered a 2GB SD card (the smallest one she offers), just in case I didn't have a compatible one. I wanted to run the electronics from the toy's existing battery compartment, which held a pair of AA cells delivering 3 volts. I'd need to boost that to 5 volts in order to run things. Lady Ada made just the thing for that, the Mintyboost, which was designed to fit in an Altoids tin and allows charging iPods and the like from a pair of AA cells. Unfortunately, it was out of stock, and I didn't have much time. Luckily, SparkFun had 'em. While I was at SparkFun, I also ordered the CPU I had chosen to run things. The Waveshield page recommends using it with the powerful ATmega328 chip, so I had a look around for something employing it. An ordinary Arduino board probably wouldn't fit in the space available, so I was looking for something small too. And SparkFun had just the thing, their Arduino Pro Mini 328. This is a tiny thing, scarcely larger than my thumbnail.
While I waited for the parts to come in, I started working on the software, using a full-size Arduino.
Done in odd hours after work and between other things, the software was slapped together. I decided to scan the SD card for sound files, counting each one as I found it, and keeping track of any that had filenames beginning with the digits 1-4. Then, when a button was pressed, if there was a matching sound file, I'd play it. Otherwise, I'd select one at random from the remaining files and play that (I initialized the pseudo-random number generator by reading a number from an unconnected analog pin). I also wrote code to blink the LEDs while the sound was playing.
Parts started to arrive as I was getting the programming to work.
Here's a pic of some LEDs on a breadboard, used to debug the LED blinking code. The blue board is an Arduino Pro, the red board is a USB-serial converter used to load and monitor code. On the left, you can see the Arduino Pro Mini in a pink antistatic bag.
The Mintyboost and the Waveshield came as kits, so I had to assemble them. In the process, I discovered why Lady Ada was out of Mintyboosts. She had just come out with version 3, and had stopped offering the older version 2, like the one I'd picked up from Sparkfun. The difference concerned resistors used to convince newer iPods to treat the Mintyboost like a real charger. For my purposes, this didn't matter at all, I just needed the 5 volts.
I got 'em assembled and started integrating the software. I grabbed the smallest SD card we had (32MB), which was more than enough room for this project, popped it in the Waveshield and fired up the software. No joy, didn't work. I figured I'd botched a solder joint when assembling it. But just in case, I tried the 2GB card. It worked! Apparently the old, camera-branded SD card didn't support the serial protocol the Waveshield uses. So I figured I'd try the 256MB card out of my camera. It worked too, so the camera got the 2GB card, and the Frankenpod got the 256MB one.
I also had issues with noise and stuttering when playing sound files. I tracked this down to my button reading code, so I just had it ignore the buttons when it was playing sound, and just watch for button presses the rest of the time.
Time to put the thing together!
First, I soldered a 6-pin header onto the CPU so I could talk to it with my USB-serial adapter, and hooked it up to the buttons on the circuit board and reinstalled the circuit board.
Then I hooked up the Waveshield. Since the Waveshield is designed to plug into a full size Arduino, it would't fit directly on the Pro Mini. This didn't matter, since there wasn't room for stacked circuit boards anyway, so I just connected them with short lengths of wire.
Then I wired up the Mintyboost.
The LEDs could be driven directly by the original 3-volt toy CPU, but they'll need series resistors running from my 5 volt electronics. Here they are, with the heat shrink tubing that will cover them.
Then I hooked them up to the little CPU board. At this point, I'd used nearly every possible connection the little board has!
I carved a rough opening in the bottom of the toy to allow access to the volume control, SD card slot, and headphone jack.
I needed to get everything to fit and stay in place so it didn't impede the rotation of the shiny spinny disk. I had at it with the hot glue gun to tack everything in place.
I put female pins on the Mintyboost output, so I could slip them on the programming pins on the CPU board to power it in operation. To load code, I unplug the Mintyboost leads and pop on the USB-serial adapter and blast the code in.
This was handy, as I had gotten the logic backwards on which songs to choose from for buttons without a numbered track. At the last minute, on a rainy night, I uploaded the fixed code and drove out to Columbia to hand it off to werewulf, who was very busy putting together costumes and packing for the con. Originally posted at Dreamwidth.org comments