Go Down

Topic: Playing .wav file from arduino uno (Read 206 times) previous topic - next topic

BangmanHackerman

Oct 11, 2016, 03:19 pm Last Edit: Oct 11, 2016, 03:28 pm by BangmanHackerman
I need to play a .wav file from a arduino uno for a science project, but i keep getting stuck on the code. I'm an absolute beginner to programming and really need help! sorry if this is something super easy to fix and I'm just to dumb to fix it.

Here is my code

Code: [Select]
#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>

TMRpcm tmrpcm;   // create an object for use in this sketch


void setup(){

 tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

 Serial.begin(9600);
 if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
   Serial.println("SD fail");  
   return;   // don't do anything more if not
 }
 tmrpcm.play("Thomas.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}



void loop(){  

 if(Serial.available()){    
   if(Serial.read() == 'p'){ //send the letter p over the serial monitor to start playback
     tmrpcm.play("Thomas.wav");
   }
 }

}


Here are the errors

D:\TMRpcm-master\examples\basic\basic.ino: In function 'void setup()':

D:\TMRpcm-master\examples\basic\basic.ino:19:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

  tmrpcm.play("Thomas.wav"); //the sound file "music" will play each time the arduino powers up, or is reset

                          ^

D:\TMRpcm-master\examples\basic\basic.ino: In function 'void loop()':

D:\TMRpcm-master\examples\basic\basic.ino:28:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

      tmrpcm.play("Thomas.wav");

I would deeply appreciate any help and advice

el_supremo

#1
Oct 11, 2016, 06:31 pm Last Edit: Oct 11, 2016, 06:32 pm by el_supremo
Those aren't errors, they are warnings - it says so right in the message. A string such as "Thomas.wav" has a default type of "const char *" which means that it can't be changed (read-only) but the play function is presumably declared to require a "char *". You can make the warnings go away by forcing the string to be of type "char *".
Code: [Select]
  tmrpcm.play((char *)"Thomas.wav");

If your code is failing to compile, those two warnings weren't the problem. Look for the error messages.

Pete
Don't send me technical questions via Private Message.

BangmanHackerman

Thanks man appreciate it, that made things clearer. I believe I found the errors


basic:11: error: expected unqualified-id before '.' token

   TMRpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc

         ^

basic:17: error: expected unqualified-id before '.' token

   } TMRpcm.play((char *)("Thomas.wav"); //the sound file "music" will play each time the arduino powers up, or is reset

           ^

exit status 1
expected unqualified-id before '.' token

Is this right?

el_supremo

Those are indeed errors.

Code: [Select]
TMRpcm tmrpcm;   // create an object for use in this sketch
You've declared an object of type TMRpcm to have the name tmrpcm. But in your code you refer to it as TMRpcm. Where you have, for example,
Code: [Select]
TMRpcm.speakerPin = 9;
change it to
Code: [Select]
tmrpcm.speakerPin = 9;

(Don't change the declaration - it is correct)

Pete
Don't send me technical questions via Private Message.

BangmanHackerman

Ok did it

Code: [Select]
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>

#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328
#include <TMRpcm.h>           //  also need to include this library...
TMRpcm tmrpcm; // create an object for use in this sketch
void setup(){

  tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail"); 
    return;   // don't do anything more if not
  } tmrpcm.play((char *)("Thomas.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}

 
Now this pops up


basic:18: error: expected ')' before ';' token

   } tmrpcm.play((char *)("Thomas.wav"); //the sound file "music" will play each time the arduino powers up, or is reset

                                       ^

exit status 1
expected ')' before ';' token

Btw sorry for relying on you so much, you are in great help.


Paul Stoffregen

} tmrpcm.play((char *)("Thomas.wav"); //the sound file "music" will play each time the arduino powers up,

Looks like you've got 3 open parens "(" but only 2 close parens ")".  Try adding another close ")" at the end.

BangmanHackerman

Just tried that, got a lot more problems now....

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'byte TMRpcm::metaInfo(boolean, char*, char*, byte)':

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1381:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   char* datStr = "LIST";

                  ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1382:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if(infoType == 1){datStr = "ID3 "; datStr[3] = 3;}

                            ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

  char* tagNames[] = {"INAM","IART","IPRD"};

                                          ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

    tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

                ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

    tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

                                      ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:59: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

    tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";

                                                           ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'void TMRpcm::finalizeWavTemplate(char*)':

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1568:65: warning: narrowing conversion of '(fSize >> 16)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

  seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};

                                                                 ^

C:\Users\olaba270800\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1568:77: warning: narrowing conversion of '(fSize >> 24)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]

  seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};

                                                                             ^

C:\Users\OLABA2~1\AppData\Local\Temp\ccOwGiMm.ltrans1.ltrans.o: In function `main':

ccOwGiMm.ltrans1.o:(.text.startup+0x84e): undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy