For a personal project, I needed a device that could play distorted audio and take cues. I could have used an off the shelf Bluetooth speaker along with a suitable phone or tablet app to provide the audio stream, but there are advantages to having it all free-standing. I also wanted the distortions to change over time, rather than being baked in to audio samples stored in files.
I used a small but powerful and inexpensive ARM based single board computer, an audio codec chip with built-in headphone amplifier, and a LiPo (lithium ion polymer) battery along with a matching USB charger module. All these pieces are commercially available modules, and fit neatly into the space I had available inside the project. The ARM provided plenty of audio-rate DSP power for processing prerecorded sounds and producing “interesting” distortions.
What am I building?
My goal is to add audio effects to a theatrical prop. The space available for electronics and a speaker is constrained, and might not be much larger than a plastic cylinder 1.5 inches in diameter and a few inches long, or perhaps a shallow space about 3 inches in diameter. The prop itself was taking shape concurrently with the electronics, so the constraints of each were to some degree adjusting the other.
Given the large number and variety of shapes of Bluetooth headset and music speaker devices on the market (and sitting in my junk bin as well) one might wonder why not simply repackage one of those. The answer lies mostly in user interface. The BT speakers I’ve played with tend to use the audio channel as their interface, announcing things like “Bluetooth open” and “Bluetooth connected” as events occur. Should such an announcement occur at the wrong moment, it would entirely spoil the mood the prop is attempting to evoke. While I could undoubtedly start from a reference design of such a device and tweak its firmware, that would still leave the prop tethered (albeit invisibly) to a cell phone. The Director would prefer to avoid both of those issues.
My size constraint is that I’d like the option to pack the whole device inside a 1.5″ ID plastic tube, with a single speaker facing out one end. The 1.5 inch maximum diameter for the speaker would also apply to the larger shallow space, which for other mechanical reasons became the natural place to put all the hardware.
Let’s go shopping
Since the release of the Arduino, there are many small, inexpensive microcontroller modules on the market.
An Arduino did not make sense for this because it is physically larger than I wanted and does not have the horsepower to do lots of audio processing in real time. There are plenty of Arduino-compatible boards that are smaller, and plenty that use more powerful processors. The aptly named Teensy board family is both.
The Teensy3 has an ARM CORTEX M4 processor, running at 96MHz, with 256K flash, and 64K RAM in a Freescale MK20DX256VLH7. It also provides a fairly rich mix of on-chip peripherals including digital and analog I/O, Timers and DMA, USB, UART, I2C, SPI, CAN, and I2S. The board is about 1.4 by 0.7 inches, and the tallest component on the board is the USB micro-B connector.
To drive a speaker I wanted some form of audio interface to hook to the I2S port. There are a number of companion boards that can connect directly to the Teensy. Two of those have audio amplifiers.
The Teensy3 Audio Adapter has an audio codec chip that provides multiple ADC and DAC channels to handle stereo audio in and out in both digital and analog forms. It also has a low power headphone amplifier, which can be used to drive a small speaker. It happens to also include a micro-SD card slot, which will be handy to hold the WAV files to play. It is about 1.5 inches square, and easily mounts the Teensy either by soldered pins or with a socket.
The Prop Shield provides a 2 watt class D mono amplifier, along with a moderately sized FLASH memory, optional 10 degree of freedom motion sensors, and drivers for serial controlled LEDs. It could be an interesting choice and without the motion sensors is substantially cheaper than the audio adapter. It is the same width as the Teensy, and a little longer providing its speaker and LED drive pins along with solid mounting holes as extensions at both ends.
For power, I’d like to use a small LiPo (lithium polymer) battery. These are rechargeable single cells that run at a nominal 3.7V, and can charge from 5V via a suitable charge controller chip. The battery is high enough voltage that a 3.3V LDO is sufficient to drive 3.3V logic like the Teensy. 5V charging means that a USB cable can be used to both charge the battery and to reprogram the Teensy’s firmware.
Adafruit sells lots of bits and pieces that are useful. They also resell the Teensy board, and so could be a one-stop shop for this project. In particular, they have a wide range of LiPo batteries and [matching chargers][lipocharger], with capacities from 100 mAh to 6600 mAh.
How I did it
Modules I used
Here are the specific modules I used.
- Teensy 3.1 with pins installed.
- Teensy3 Audio Adapter with optional 25K potentiometer and 14-pin sockets.
- Micro Lipo – USB charger which I modified to attach it to
Vusb
,Vin
, andGND
on the Teensy. - 500 mAh LiPo Battery
- 1.4 inch diameter 8 ohm speaker
Wiring
With pins on the Teensy’s underside, I mounted the sockets to match on the top side of the audio adapter. Using sockets added to the height, but also permitted removing the Teensy to make additional connections as needed.
I included the optional pot on the audio adapter on the assumption that having at least one parameter that could be adjusted live would be useful. I used it for a volume control.
I modified the Teensy by cutting the jumper that separates Vin
from Vusb
, and connected Vin
(via a power switch) to the BAT+ terminal on the charger. Vusb
and GND
wired directly to the charger, making use of the nice large pads intended to be a USB A connector. With this change and a battery connected, the battery powers the Teensy unless the USB is attached. With a USB cable connected to the Teensy, the battery also charges.
I chose not to place the solder jumper on the charger that would up its charge rate from 100mA to 500mA. If the battery were larger, that might be a desired change, but with a 500mAh battery it is not necessary. The general recommendation with these batteries is to not charge them faster than 1C in any case, so with this battery, setting that jumper would set it to exactly 1C charge rate.
I tested the firmware with just headphones plugged in to the jack on the audio adapter. For installation, I found a suitable speaker in my parts bins, and soldered it to the headphone L
and VGND
pins. As noted in the silkscreen and documentation, I was careful to avoid accidentally shorting VGND
to GND
. I chose to ignore the R
output entirely, but arranging to sum L
and R
and drive the speaker from both might allow doubling the power delivered to the speaker.
Modules I would recommend instead
The Teensy 3.2 is the current version, and is completely compatible. Use that.
The Backpack Charger provides much handier holes for wiring than the Micro Lipo – USB charger does, and is smaller as well. If you needed a USB connector on the charger, then either the Micro Lipo w/microB or Mini Lipo w/miniB would be good choices.
There are other size options for batteries, depending on your required runtime and space in your project. You might not require a battery at all, in which case any USB charger will plug into an unmodified Teensy and power it just fine.
Make some noise
The Teensy has been well-integrated into the Arduino IDE, despite being a completely different CPU architecture. This makes it easy to get started.
- Install the Arduino IDE. Be sure to let it install any USB drivers it needs, and launch it once to make sure it runs. Exit before proceeding.
- Install Teensyduino. Its installer should locate the Arduino IDE on its own, but it will ask for help if it finds more than one possibility. Let it install any additional USB drivers it offers. (Note that there are more details, especially for Linux and Mac platforms. Read the linked page for the full installation instructions.)
- Plug in the Teensy and notice that the LED blinks.
- Play through the tutorials and with any examples that interest you. This is a good way to get familiar with the Teensy, the audio adapter, and the Arduino IDE.
Now, write the real firmware, noticing along the way that some buttons and a power switch would be nice to have. Make those hardware changes, and then add code to support the buttons as cues. All of that is left as an exercise to the reader, and to a future post.
To foreshadow, I used the Teensy Audio library and a new synthesized signal source for the primary signal path. Recorded sounds came from uncompressed 16-bit PCM WAV files stored on a µSD card via the SD library. I also used the Bounce library to handle a couple of pushbuttons for cuing.
Summary
I needed to make some sounds from inside a prop without much room to spare. A commercially available ARM CORTEX M4 module provided all the audio DSP horsepower needed and fits inside the opening.
A future post will describe the firmware I wrote based on the provided audio processing library.
If you have a project involving embedded systems, micro-controllers, electronics design, audio, video, or more we can help. Check out our main site and call or email us with your needs. No project is too small!
+1 626 303-1602
Cheshire Engineering Corp.
710 S Myrtle Ave, #315
Monrovia, CA 91016
(Written with StackEdit.)