Some small experiments with Arduino sound…
Last year, I spent a little bit of time to create a set of blinking Christmas lights that I could mount in a hat. It was powered by an ATtiny13 and mounted in an Altoids tin. While setting up my Christmas tree last weekend, I found them, and they still work. In case you missed it, here are some of the videos I did at the time:
It was kind of fun, and still works, so I’ll probably be wearing it around. But I thought to myself: what could I do to make it better?
The obvious thing to me was to try to add more lights, more patterns, and music. Rather than use a naked ATtiny13, I thought that I would just go ahead and use an Arduino. I have an Arduino Mini that I got to use in a radio beacon experiment that I haven’t gotten to yet, so that seemed like a good idea. The question was then: what could I do?
I came up with these ideas:
- More lights. At $.99 a string, I could put a lot more light strands in place. That would make fancier “chase” effects possible, and generally just look cool.
- More effects.
- A better hat! The missus has a new sewing machine, and could probably use a new project. I have a big head, so finding a Santa cap that fits is always a bit of a chore, and if we made our own, we could add pockets for batteries and sew in the wiring to make it neater.
- Sound. It would be cool to add a small speaker and amplifier, and play music with synchronized light effects.
I don’t think any of this is especially hard. The only part I hadn’t really done before (other than the sewing bit) was sound. So, last night I started reviewing what libraries existed for sound on the Arduino. I actually have a WAV shield lying around, but I was looking for something a bit more minimal: I didn’t really care to use a full shield, both for size and for just a sense of minimality. I kind of wanted to store a few Christmas tunes in the on-chip flash, and then synthesize some high quality (well, decent quality) audio directly.
Which lead me to the Mozzi sound framework.
Mozzi seems to generate some pretty cool sounds (samples here) and is a pretty neat framework. I decided to give it a whirl last night. I was somewhat delayed by trying to get the Arduino software installed on my new Windows 8 laptop. Apparently the drivers that you need aren’t sufficiently digitally signed for Microsoft to trust them, and you have to go to some effort to disable those checks and get them to install. But once I got that sorted out, I didn’t have any problem downloading and playing with the Mozzi library. To hear the samples, I just hooked a high impedance earphone from a crystal radio to pin 9 and ground, and they worked as expected. The Mozzi webpage actually recommends a bit of output filtering: they have a 6Khz lowpass filter followed by a 16Khz notch filter to get rid of the PWM noise. The design is quite simple RC filter and uses very common values of components, so it should be pretty easy to build. I spent a few minutes entering the schematic into LTSpice, and it seems like it works as expected, and should help audio quality considerably.
Going forward, I need to find some decent Christmas tunes (perhaps in ABC notation like these, although I’d like more complex, polyphonic tunes) and figure out how to synthesize some nice sounds in the incredibly limited time available, as well as control the switching of the LEDs themselves. Stay tuned for more experiments.