Need help with Audio Code

This is my first time using an Audio UNO R3. My board is working. I am able to use the basic Blink sample. I am trying to teach my self the code. My goal is to play WAV audio and control the out puts. Can someone please help me with a code.

Input -Pin (0) RXD, Pin (1) TXD (WAVE Music)

Output to Control Pins, 2,3,5,6,7

I am trying to make music controlled Christmas light display.

Thank you.

If you are going to play WAV (or MP3) files, you’ll need some additional hardware. Look for an “Audio Shield”. (“Shields” are add-on boards for the Arduino.) If the audio board doesn’t contain memory, you’ll also need additional memory to store the WAV/MP3 file (due to the Arduino’s limited flash storage).

I am able to use the basic Blink sample. I am trying to teach my self the code.

Take a look at the [u]Blink Without Delay Example[/u]. I most real-world programs you’ll want to avoid delay() because the processor can’t do anything during the delay time.

When you think you “get” the Blink Without Delay example, try adding another LED with it’s own separate timing and blink two LEDs at the same time, but at different blink rates.

Read through the [u]Arduino Language Reference[/u], and work-through some of the examples. You may not understand it all, but it will give you an idea of what you can do, and how things are done. And, it’s not that long so it won’t take you too long to read-through the whole thing.

If you’ve never programmed before, the most important programming concepts are looping (doing things over-and-over) and If-statements and conditional branching (i.e. If this, then do that). There’s a LOT more to programming, and a LOT more to the C/C++ language, but once you understand those concepts, you’ll have a good understanding of how to do things in software.

Playing WAV files will take an additional library, but that can wait.

Thank you. I ordered the Audio Shield today. I was also playing with the Example Blinking code. I was able to add more pins and change the timing / delay of the blinking. Does anybody know where I can find the code for Audio Shield.

Hi there. I am the creator of the RaspiVoice project on Kickstarter . When I initially started this project it was my intention to use Arduino for playing WAV files. But I soon ran into a few issues. Here is a summary of my experiences:

  • Arduino Uno sound playback using PWM technique - I quickly abandoned that idea because the sound quality was really bad.
  • Arduino Uno using MP3 shield - The shield I got wanted you to use numbers for the files instead of file names.
  • Arduino Due with DAC outout - Did not work for me either. After spending a lot of time connecting up an SD card, I found with some frustration that I still had some limitations:

  • File size limitation. The file names are limted to only 8.3 format which was unsuitable for my requirement

  • Sound quality.When I play a number of short sound files it starts of sounding good but quite detoriorated to a point where it was completely distorted. I had work-arounds to overcome the problem, but could never find the true cause of it.

  • Popping sounds. There was a distintt popping sound at the start and end of each sound file which was driving me nuts. It was definetely not th WAV files I used that were responisble for this popping sound.... I suspect the Arduino library just played the header and footer part of the WAV file and that is what caused it.

  • Arduino Yun - This worked actually quite well, but the Yun was just too expensive for what I had mind.

  • Raspberry Pi - This worked by far the best and even as an old Arduino fan I had to admit this was the best solution for my requirments.

It was only after I tried all kinds of Arduino options that I eventually tried using a RaspBerry Pi simply as a WAV player and hook it up via serial interface to my Arduino. It worked really well. The Raspberry Pi costed me only $25 and already had everything I needed... SD card, audio output, etc. This was even cheaper that using a shield and gave a lot of extra benefits. And since the Raspberry Pi then does all the audio processing etc, it meant I did not need any additional libraries, shields etc on my Arduino. Just use simple Serial.Println with a filename to play any WAV file. In fact it worked so well that decided to turn it into the RaspiVoice product.

A friend of mine also suggested the Raspberry Pi. However I all ready bought the Audio Shield. But I will make that my next purchase in the future. I just need to find a Audio shield library. Do you have any to share?

Ok , So I spent the last 2 hrs playing with the code. It uploads with no errors. Now I just need my Audio shield board to test it.

/*
This code is show how Arduino Wave Module works with Arduino.
Code is not optimized. Any improving work on it is encouraged.
Modified by USMC Junglist - Semper-Fi
*/

int CLK = 8;
int DAT = 9;

void setup() {
pinMode(CLK, OUTPUT);
pinMode(DAT, OUTPUT);

pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

}

void loop() {
send(0x0000);//play file 0000
Serial.println(“Play 1”);
delay(10000);//delay 1 seconds

send(0x0001);//play file 0001
Serial.println(“Play 2”);
delay(10000);//delay 1 seconds

send(0x0002);//play file 0002
Serial.println(“Play 3”);
delay(1000);//delay 1 seconds

send(0x0003);//play file 0003
Serial.println(“Play 4”);
delay(1000);//delay 1 seconds
send(0x0004);//play file 0004
Serial.println(“Play 5”);
delay(1000);//delay 1 seconds
send(0x0005);//play file 0005
Serial.println(“Play 6”);
delay(1000);//delay 1 seconds
send(0x0006);//play file 0006
Serial.println(“Play 7”);
delay(1000);//delay 1 seconds
send(0x0007);//play file 0007
Serial.println(“Play 8”);
delay(1000);//delay 1 seconds
send(0x0008);//play file 0008
Serial.println(“Play 9”);
delay(100);//delay 1 seconds
send(0x0009);//play file 0009
Serial.println(“Play 10”);
delay(1000);//delay 1 seconds
send(0x0010);//play file 0010
Serial.println(“Play 11”);
delay(1000);//delay 1 seconds
send(0x0011);//play file 0011
Serial.println(“Play 12”);
delay(10000);//delay 1 seconds
send(0x0012);//play file 0012
Serial.println(“Play 13”);
delay(1000);//delay 1 seconds
send(0x0013);//play file 0013
Serial.println(“Play 14”);
delay(1000);//delay 1 seconds
send(0x0014);//play file 0014
Serial.println(“Play 15”);
delay(1000);//delay 1 seconds
send(0x0015);//play file 0015
Serial.println(“Play 16”);
delay(1000);//delay 1 seconds
send(0x0016);//play file 0016
Serial.println(“Play 17”);
delay(1000);//delay 1 seconds
send(0x0017);//play file 0017
Serial.println(“Play 18”);
delay(1000);//delay 1 seconds
send(0x0018);//play file 0018
Serial.println(“Play 19”);
delay(1000);//delay 1 seconds
send(0x0019);//play file 0019
Serial.println(“Play 20”);
delay(1000);//delay 1 seconds
send(0x0020);//play file 0020

send(0xfff0);//set voice volumn to 0 (turn off)
delay(3000);

send(0xfff4);//set voice volumn to 4
delay(3000);

send(0xfff7);//set voice volumn to 7
delay(3000);

send(0xfffe);// pause
delay(5000);
send(0xfffe);//play
delay(5000);

/*
//the following code is to play previous track
digitalWrite(11, LOW);
delay(100);
digitalWrite(11, HIGH);

//the following code is another way to pause and play
digitalWrite(12, LOW);
delay(100);
digitalWrite(12, HIGH);

//the following code is to play next track
digitalWrite(11, LOW);
delay(100);
digitalWrite(11, HIGH);

*/
while(1);
}

/****************************************************
The following function is used to send command to wave shield.
You don’t have to change it.

Send the file name to play the audio.
If you need to play file 0005.AD4, write code: send(0x0005).

*****************************************************/
void send(int data)
{
digitalWrite(CLK, LOW);
delay(2);
for (int i=15; i>=0; i–)
{
delayMicroseconds(50);
if((data>>i)&0x0001 >0)
{
digitalWrite(DAT, HIGH);
//Serial.print(1);
}
else
{
digitalWrite(DAT, LOW);
// Serial.print(0);
}
delayMicroseconds(50);
digitalWrite(CLK, HIGH);
delayMicroseconds(50);

if(i>0)
digitalWrite(DAT, LOW);
else
digitalWrite(DAT, HIGH);
delayMicroseconds(50);

if(i>0)
digitalWrite(CLK, LOW);
else
digitalWrite(CLK, HIGH);
}

delay(20);
}

http://youtu.be/TRksFeuEiPw