This is a short introduction on how to play sounds through the Intel Edison board when using Arduino as a programming environment.

Since the Arduino board for Intel Edison doesn't have any sound capbabilities, we'll use a cheap Bluetooth speaker (we're using a tiny usb-chargeable speaker called the X - Mini, but any should do).

There's these steps to get music playing on your Edison board with Arduino code:

  1. Connect the bluetooth speaker for the first time
  2. Connect to the speaker subsequently through Arduino
  3. Transfer / download sound clips
  4. Play sounds through the Arduino environment.

Step 1: Connect the Bluetooth Speaker for the First Time

We will follow this tutorial from the Intel Internet of Things site:

Connect to Bluetooth on Intel Edison

In essence, we want to connect to the command line on our Edison board, and run several commands that enable and connect to the Bluetooth speaker on it.

Instead of copying files from your computer via SCP, you can also copy them directly from the internet, as explained in step 3. First, we'll explain how to replicate the connection process through Arduino when your board boots up.

Step 2: Connect to the Bluetooth Speaker Subsequently Through Arduino

Once you've set up your speaker through the command line, you only need to send the following commands to reconnect to it subsequently (ie., if either the speaker or the Edison board was switched off in the meantime):

rfkill unblock bluetooth

Also, you'll need to open bluetoothctl and connect to your device:

bluetoothctl<br>>> connect 30:21:0F:92:E3:16<br>>> quit

Important: You'll need to replace the identifier of the Bluetooth device with the one of your device, which you've learned from scanning for it in the previous step!

We can send these commands from our Arduino environment by calling the system() function in our setup() routine:

setup()<br>{<br>    system("rfkill unblock bluetooth");<br>    delay(100);<br>    system("bluetoothctl <<< 'connect 30:21:0F:92:E3:16'");<br>}

This should connect our bluetooth device. In our experience, it was fairly reliable, but sometimes we had to boot the Arduino environment twice (using the RESET SHIELD button on the Edison board).

An alternative I've found online is this command, although we had no luck with it:

system("echo -e 'power on\nconnect \t \nquit' | bluetoothctl");

Once you've connected your speaker, we can start to play some sounds!

Step 3: Download Sound Clips

The easiest and fastest way we have found to transfer sound clips onto our Edison board is using wget through the command line. For this to work, connect to your Edison-board like in Step 1, make sure it's connected to the internet through wifi (there are several tutorials on this, the simplest might be to call configure_edison --wifi) and simply type:

wget  http://your-url-to-music.com/mymusic.wav

For example, using sounds from http://themushroomkingdom.net/:

wget http://themushroomkingdom.net/sounds/wav/smb3/smb3_power-up.wav

The file should download right away to your /home/root/ directory. You can now test playing by typing:

gst-launch-1.0 filesrc location= /home/root/smb3_power-up.wav ! wavparse ! pulsesink

In the next step, we'll explain how to do this from within the Arduino environment.

Step 4: Play Sounds Through the Arduino Environment

As we've explained in the last step, we've been playing sounds through the gst-launch-1.0 command. We can simply call this using the system() command from within Arduino:

system("gst-launch-1.0 filesrc location= /home/root/smb3_power-up.wav ! wavparse ! pulsesink");

To make things a bit prettier, we can wrap this file in a function:

void playSound(String file)<br>{ 
    String s = gst-launch-1.0 filesrc location= /home/root/" + file;
    s += " ! wavparse ! pulsesink";

And simply call it like this:


Good luck!

<p>Cool Edison project.</p>

About This Instructable




More by RobinB112:Playing sound with the Intel Edison and Arduino using a Bluetooth speaker 
Add instructable to: