Add audio/speaker to Arduino Yun

Hello:

I'm building a speaker with Arduino Yun. That is, it would play audio files stored on the sd card. I've been using a USB sound adapter and a speaker. But I wonder if there is any other way to play audio besides using the USB. If I want to turn this toy project into a real one, this method of using a USB sound adapters seems like overkill. It almost looks like that I might be able to connect an audio amplifier module straight to some of the pins but I'm just not sure how to do it.

Thank you very much in advance!

You could hook an audio amplifier and speaker to a shield output pin, and drive it from a sketch. But all you are going to get are some basic tones and beeps, and nothing that is recognizable as your original audio files. To get reasonable audio playback, you need to be able to read the file, decode the audio data (which requires some significant processing) and output the resulting audio samples to a DAC (a true analog output, not the simulated PWM output available through analogWrite().) The '32U4 sketch processor does not have the speed or throughput to be able to do all that. The Linux processor does, but does not have access to the shield connectors, hence the use of a USB adapter.

There are Arduino compatible shields available, but all of the ones I’ve found have their own sound processing chip that accesses it’s own SD card. That chip does all the processing, the Arduino just tells it what to play, and when. With all of the logic on those shields, they are commensurately expensive, and I’ll bet you’ll find that the USB adapter run by Linux is the least expensive and most practical solution. But that’s just one guy’s opinion…

Driving audio with usb is not overkill at all, all the processing is done by the linux side. As Shape mentioned, the atmega32u4 doesnt have resources to do that, and buying a shield will add another ic that will do the job, and is expensive compared to a 4 usd audio usb card.

ShapeShifter:
::::SNIP::::
To get reasonable audio playback, you need to be able to read the file, decode the audio data (which requires some significant processing) and output the resulting audio samples to a DAC (a true analog output, not the simulated PWM output available through analogWrite().)
::::SNIP::::

@ShapeShifter,
I was thinking maybe PWM out 8 digital I/O pins, but I'm not sure about the amount of time between writes - as writing to 8 ports may not work. It may sound weird.

FWIW, when I got start many, many years ago, one of the first projects we did was playing audio via the Printer port on an 8088 and 286 PC. Yes - bit bang PWM on the printer port. My guess is it might sound weird on the Yun.

We saw a few competitors with similar devices, but they always used capacitors to quell the BUS line noise that was present on the PC. We quelled line noise by trimming one of the bits (I think low). We used an R2R ladder, then (I think) we trimmed the low bit.

May be some sort of bit shifter might work for this?

Jesse

jessemonroy650:
FWIW, when I got start many, many years ago, one of the first projects we did was playing audio via the Printer port on an 8088 and 286 PC. Yes - bit bang PWM on the printer port. My guess is it might sound weird on the Yun.

While slow for this day and age, both of those systems are 16-bit processors and more powerful than the '32U4. While you can play some sophisticated tricks to get some sound out, I'll bet that you abandoned your printer port audio as soon as the superior SoundBlaster cards came out, right?

It really depends on the OP's sound quality needs: by using a USB audio adapter to play files, I'm assuming he wants good sound quality. But if the sound requirements don't need high quality, (buzzy/distorted sound is OK or just simple beeps are needed) then there could be work-arounds that don't need the USB interface. But these are likely to use up quite a bit of the sketch's processor time.

I guess we really need to know more about the OP's actual sound requirements.

ShapeShifter:
While slow for this day and age, both of those systems are 16-bit processors and more powerful than the '32U4. While you can play some sophisticated tricks to get some sound out, I'll bet that you abandoned your printer port audio as soon as the superior SoundBlaster cards came out, right?

::::SNIP::::

@ShapeShifter,
actually our sound was superior to that of all sound cards that used 8 or 16 bit buses. They always had the crappy card bus to contend with. We actually had a heads up competition with one of the sound cards, and our sound device was superior. They could only kick our ass by playing CD roms. Later buses proved to fix that problem, usually a 32-bit bus - like micro channel.

We sold the project to a sales person, who did a better job of marketing our product. We saw him do triple our sales with a stereo system, and the product sold in baggies and photocopied directions. We had professional looking bags and instructions. It just proved we were lousy sales people. We called our product "audio byte" (competitor went by "sound byte"). The guy that bought our product changed the name to "Maestro". Shows what we know.

Jesse

jessemonroy650:
We sold the project to a sales person, who did a better job of marketing our product. We saw him do triple our sales with a stereo system, and the product sold in baggies and photocopied directions. We had professional looking bags and instructions. It just proved we were lousy sales people. We called our product "audio byte" (competitor went by "sound byte"). The guy that bought our product changed the name to "Maestro". Shows what we know.

Great story :slight_smile:

...R