Arduino Forum

Using Arduino => Audio => Topic started by: DanJennings on Apr 18, 2018, 07:38 pm

Title: .WAV file cannot be played
Post by: DanJennings on Apr 18, 2018, 07:38 pm
I am attempting to make a motion activated .WAV player using an Arduino Uno. I am using a TMRpcm program to play the .WAV file and have a SD card reader module connected to the Arduino's 5V supply. The .WAV file is 16000 Hz 8 bit mono. The program has no actual errors present during compiling or uploading, only the  "deprecated conversion from string constant to 'char*' ". When attempting to play the file I got the println text telling me that there was no file. I tested the SD card reader by uploading a program that would read and open a .TXT file which proved the SD card reader is functional, I also tested the two 4 Ohm speakers and they also work. When using an audio player program, the middle two pre-installed LEDs faintly glow red before the led on the right glows red. I will leave a copy of the program below for you to examine. Is there anything that could be suggested that might be causing this problem from what I have described so far? Any answers and/or suggestions would be greatly appreciated and I will be posting the program for more insight on the issue. Thanks.
THE PROGRAM:

#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("jugg.wav"); //the sound file "jugg" 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("jugg.wav");
    }
  }

}
Title: Re: .WAV player problems
Post by: MarkT on Apr 18, 2018, 08:13 pm
Change the test program to read/open the .wav file...  If that works compare that code to your other one and
make sure its doing the same stuff for the SD card.  RAM usage could be an issue, use verbose mode for upload
and read the output to see if memory is tight?
Title: Re: .WAV file cannot be detected
Post by: DanJennings on Apr 18, 2018, 08:23 pm
Okay, thanks! Ill make sure to try this out when I can.
Title: Re: .WAV file cannot be detected
Post by: el_supremo on Apr 18, 2018, 10:35 pm
The WAV filename on the SD card must conform to 8.3 format. Long filenames won't work.

Pete
Title: Re: .WAV file cannot be detected
Post by: DanJennings on Apr 19, 2018, 05:58 pm
Well, this explains a lot actually! The file name is long, so ill have to try shortening it. Thanks a lot for your help!
Title: Re: .WAV file cannot be detected
Post by: MarkT on Apr 20, 2018, 02:14 am
long filenames in FAT filesystems are a massive bodge and tend not to be supported by embedded devices,
accident of history...
Title: Re: .WAV file cannot be detected
Post by: DanJennings on Apr 21, 2018, 09:14 pm
Unfortunately, making the filename shorter didn't help. Thank you for your suggestion anyways. I posted the program so hopefully there is something that you can find wrong with it. Also, I forgot to mention, The two middle LEDs on the UNO faintly glow red as if they try to light up but cannot. What would this mean and would that be a part of the problem?
Title: Re: .WAV file cannot be played
Post by: MarkT on Apr 24, 2018, 09:35 pm
Try using all CAPS for 8.3 filenames
Title: Re: .WAV file cannot be played
Post by: DanJennings on Apr 26, 2018, 05:58 pm
Alright, hopefully this works... Thanks for your help!
Title: Re: .WAV file cannot be played
Post by: hasanbajwa on Apr 27, 2018, 09:13 pm
thanks for (WAV file cannot be played) post. i helped me a lot.
Title: Re: .WAV file cannot be played
Post by: 6v6gt on Apr 29, 2018, 07:14 am
Just to add to the general experience, I spent a few hours yesterday struggling to use the library TMRpcm. I discovered the problem only when I used another SD card program to read the card and print out the first few 100 bytes of the .wav file. In the file I saw the text "Microsoft encryption provider" or similar and it dawned on me that I had copied the file from a PC where the encrypting file system was active. Anyway, I've now got that working and am now hacking the library so you jump into a .wav file in increments of one hundredth of a second (instead of the current one second).