Easy Button Hacking

By: paul

2011-04-21 12:40:45

Yesterday I got the urge to hack a Staples Easy Button.... Read on for details + code.... This little hack uses a PWM from Teensy to play audio. The audio is 8 bit and the sample rate is 7.8 kHz, which is plenty for the cheap speaker in the easy button. With about 28K of memory left over (the code is tiny), Teensy can hold about 4 seconds. Here is the complete source code. The makefile runs "sox" (just a quick apt-get away on Ubuntu) to convert a wav file to raw bytes at 7.8 kHz, and then a perl script turns it into a header that's included right into the code. The code just turns on the PWM and interrupt. Each sample is played for 4 PWM periods, so the PWM carrier is 31 kHz, which is easy to filter out and nobody could hear even if not filtered (and that cheap speaker could reproduce it anyways). The audio amp is a LM4902, which I had left over from another project. It turns out that chip is now obsolete, but it looks like a LM4889 is a direct (and superior) replacement. That little amp board has a 2 stage RC filter and then the amplifier. It's intended to stack as a 'shield' on top of Teensy, but there was limited vertical space inside the easy button, so I mounted it separately and ran wires. PCB files for the amp board - if you want one (or 3), send these to the PCB Group Order. Here are placement diagrams for building that little amp board. Sorry, I didn't draw a schematic. It turns out lots of other people have hacked the easy button other ways, probably easier ways. But I did it in 1 morning using only parts that were laying around, left over from other stuff. I also never published this audio playing code and little filter+amp board... until now. This (blog post) was also a bit of an experiment to try the openshot video editor. I'm using version 1.2.2 as packaged by ubuntu 10.10. Openshot was indeed very easy to get started using. On the other hand, within minutes I hit sound bugs, where the sound would be out of sync or wouldn't play at all while previewing. For over a year I've been intending to "get into doing video" for tutorials. I tried final cut express at one point, and didn't really like it much, though I only got part way up its steep learning curve. Openshot really looks nice, though I've seen reviews that mention it still has a number of bugs and stability issues. Since I mainly use Linux, I'm really hoping openshot will mature. Especially somethings so fundamental as having the sound in sync (hope else can you figure out where to trim off the rest of a clip) is pretty important. Well, enough rambling.... this thing was a fun little distraction from some very difficult coding I've been doing in Teensyduino, to allow the user to claim the disk from USB (when Teensy is acting as a USB disk) so it can accessed with the Arduino's SD (sdfat) library. It's tricky because a scsi transaction level locking is needed (one transaction can span many USB packets) and then session level sharing is needed (eg, the PC is properly informed of a media removal and return). Unlike Dean's LUFA library and Atmel's example, where everything happens under the programmer's control, Teensyduino implements all USB disk stuff "in the background" so it can extremely easy for Arduino users..... but it makes implementing 2 layers of mutual exclusion very tough. So, enough easy button, it's back to work for me!!
Back to archive index