I have the latest version from the wiki, 1.03. I can upload and run the examples and the MostFunctionDemo successfully plays the files off of the SD card that I converted using the provided tools.
I am creating a phone that plays a specific audio file based on if they put in the correct phone number. I have everything working except the playback.
I am using the same arduino for the MostFunctionsDemo and my own project so the pins and everything hooked up to the board are correct.
I am using the tone() to play a dial tone and as a test I put in the code to play a file off the SD card for the dial tone instead and it successfully plays in the loop() function as the dial tone. I did notice that if I 'hang up' the phone then pick it back up my serial.print statements run that it is playing the sound but there is no audio. If I reset the arduino and it is the first time it is a dial tone, it works fine.
I am using the Keypad and Password libraries to detect the password and use the keys on the phone, all of that is detected correctly and I have a switch statement if they press the # it resets the password attempt and * evaluates the password. When they evaluate it will either pass or fail. I put the entire code block from the example in function call based on if they pass or fail and it seems to get stuck.
This is the code I am using:
if (file == "PASS.AFM") {
Serial.print(F("Looking for ... PASS.AFM"));
if (!SdPlay.setFile("PASS.AFM")) {
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
while (1);
}
} else if (file == "PASS.AFM") {
Serial.print(F("Looking for ... FAIL.AFM"));
if (!SdPlay.setFile("FAIL.AFM")) {
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
while (1);
}
}
// Start playback
Serial.println(F("File set, no errors, playing file"));
SdPlay.play();
// Let the worker work until playback is finished
while (!SdPlay.isStopped()) {
}
It prints out the Looking For message and completely freezes up. It never prints out an error or anything. I have to reset the arduino to do anything else.
I put print statements in the SimpleSDAudio.cpp file:
boolean SdPlayClass::setFile(char *fileName) {
//Serial.print(F("Setting file to "));
Serial.println(fileName);
// Serial.print(F("_pBuf: "));
if(!_pBuf) {
_lastError = SSDA_ERROR_NOT_INIT;
Serial.print(F("_lastError: ")); Serial.print(_lastError); Serial.println(F("should return false"));
return(false);
}
// Serial.println(F("uint8_t retval..."));
uint8_t retval;
// Serial.println(F("stop()..."));
stop();
// Serial.println(F("_fileinfo.Size = 0..."));
_fileinfo.Size = 0;
Serial.println(F("SD_L2_SearchFile..."));
retval = SD_L2_SearchFile((uint8_t *)fileName, 0UL, 0x00, 0x18, &_fileinfo);
Serial.print(F("retval: "));
if(retval) {
Serial.println(F("should return false"));
_lastError = retval;
return(false);
} else {
Serial.println(F("should return true"));
return(true);
}
}
It will get to the SD_L2_SearchFile line and stop, sometimes... Other times it will print "retval: " and stop.
I use this same code when uploading the demo and it will print everything and work successfully.
I thought it might be a memory issue, but my program compiles with this:
Sketch uses 12,404 bytes (38%) of program storage space. Maximum is 32,256 bytes.
Global variables use 636 bytes (31%) of dynamic memory, leaving 1,412 bytes for local variables. Maximum is 2,048 bytes.
and the demo is this:
Sketch uses 9,902 bytes (30%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,341 bytes (65%) of dynamic memory, leaving 707 bytes for local variables. Maximum is 2,048 bytes.
So I can't believe that it is a dynamic memory issue. The files play in my project when they are set to play immediately as the 'dial tone'.
The files I am trying to play are PASS.AFM which is 150KB and FAIL.AFM which is 163KB. Now that I am looking again the EXAMPLE.AFM is 824KB so I do not think that the size of the sound file has any impact on the program storage space or dynamic memory it seems.
I have programming experience but am new to the Arudino and any caveats there might be.
please advise. If more information is required I will provide it. I tried to be as thorough as possible.