element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum SimpleSDAudio playback issue on Arduino Uno
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 1 reply
  • Subscribers 391 subscribers
  • Views 448 views
  • Users 0 members are here
  • audio
  • simplesdaudio
  • SD card
Related

SimpleSDAudio playback issue on Arduino Uno

Former Member
Former Member over 9 years ago

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.

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 9 years ago

    I figured it out. I moved the initialization of the SD card to right before I need to play the file and I deInit() it after it is played. This prevents it from freezing up on me.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 9 years ago

    I figured it out. I moved the initialization of the SD card to right before I need to play the file and I deInit() it after it is played. This prevents it from freezing up on me.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube