Arduino Yún with SOUND the supereasy way

At the Codemotion in Milano, I had a chat with Federico Vanzati from Officine Arduino, and he gave me the fantastic idea to try to use a supercheap USB Audio card with Arduino Yún to give to it full audio capabilities with zero effort.

And suddenly I was like…

image

I mean, it’s awesome! It could give me (and hopefully to you) infinite new possibilities! Sound with Arduino with no external libraries or crappy MP3 shields? How great could it be? Now that we have a great Wi-Fi support thanks to the Yún, this was the real missing feature!

I started with buying this sound card (http://www.manhattan-products.com/hi-speed-usb-3-d-sound-adapter)

Then, all I had to do was plug the sound card in, open an ssh session to the yun, and type:

opkg update
opkg install kmod-usb-audio
opkg install madplay

End of the story. Now you have sound support on the Arduino Yún. I only tried MP3 playback, I didn’t try to record some audio yet, but I’ll try soon!

To test it just copy an mp3 audio file (I named it ItCouldWork.mp3) in the root folder, or, even better, in the SD card, then upload this sketch

#include <Process.h>

const int buttonPin = 2;
const int ledPin =  13;

int buttonState = 0;
Process p;

void setup() {
  Bridge.begin();
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);     
  Serial.begin(57600);
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {     
    digitalWrite(ledPin, HIGH);  
    p.runShellCommand("madplay /root/ItCouldWork.mp3");
    while(p.running());  
    Serial.println("it works!");
  } 
  else {
    digitalWrite(ledPin, LOW); 
  }
}


It’s based on the button example, so you have to connect a pushbutton to the digital Pin 2.

image

Now, connect the sound card to the speakers and… push the button!

Magic, isn’t it?

It doesn’t sound too bad, actually the sound quality is good! And the delay is very short! I mean, it’s just the first experiment, we can work on it!

I really hope this will amaze you as it amazed me… I’m superhappy!

Many thanks to my friend and coworker Massimo, that knows Linux better than I know myself.

Bye!

Jeko

Notes

  1. mikamayhem posted this