Adding an audio channel to your microcontroller project can mean a pile of extra components and a ton of processing power, as a compressed stream must be retrieved and sent to a dedicated DAC. Or if you are [rdpoor], it can mean hooking up a low-pass filter to the UART that’s present on even the simplest of devices, and constructing a serial data stream that mimics PWM audio.
WART is a Python script that converts a WAV file into a C formatted byte array that can be baked into your microcontroller code, and for which playback is as simple as streaming it to the UART. The example uses a Teensy and a transistor to drive a small speaker, we’re guessing that better quality might come with using a dedicated low-pass filter rather than relying on the speaker itself, but at least audio doesn’t come any simpler.
The code can be found in a GitHub repository and there’s a few recordings of the output in the files section Hackaday.io page, one is embedded below. It’s better than we might have expected given that the quality won’t be the best at the PWM data rate of even the fastest UART. But even if you won’t be incorporating it into your music system any time soon we can see it being a useful addition for such things as small warning sounds. Meanwhile if persuading serially driven speakers to talk is of interest, there’s always the venerable PC speaker.
You have been “Rick rolled.”
https://en.m.wikipedia.org/wiki/Rickrolling
Thanks for sharing your secret knowledge of these obscure “internet memes”.
Thanks for providing an example of the obligatory comment field put down :)
Uh oh. The comment section has become self aware.
Nice project.
However, implementation could be improved in few ways :
– Instead of using simple oversampling (x10, from the python script), use sigma delta to increase ENOB (and theb play 16bit wav file, as below 10 bits, audio is rather mediocre)
– The sigma delta could be computed on the script processing wav and generate large binary but is less demanding on the target CPU, or the other way around.
– add a large (10uF) capacitor in serie with the voice coil and stop heating the room
@Tweepy: Absolutely! I intentionally created the project to (a) be as absolutely as simple as possible [six lines of Arduino code, two external components], and (b) leave lots of room for other people to invent improvements!
Here’s some prior art from years ago, getting the best possible audio from a single pin on a microcontroller connected to a simple low-pass filter: https://www.romanblack.com/btc_alg.htm
I love that guy’s work!
Holy moley, crafting a UART stream to mimic PWM audio is pretty nifty.
This is new to me and I think it is awesome! sure, it is not a solution to music playback but for microcontroller appropriate sounds and voice messages this is awesome.
Way cool project but I’ve been wrestling trying to convert a wave file do you have a detailed procedure you can share?