I'm getting Error code 2 with mp3 player V15 sparkfun

Hi I’m trying to play music with the mp3 shield player but i’m getting the error code 2 and I’m stuck there.
I’m using the example File player and this is what I get.
Received command: l
Music Files found :
00001: track001.mp3
00002: track002.mp3
Enter Index of File to play
Time since last command: 0.37
Enter s,1-9,+,-,>,<,f,F,d,i,p,t,S,b,m,e,r,R,g,k,O,o,D,V,B,C,T,E,M:,l,h :
Received command: f
Error code: 2 when trying to play track
Time since last command: 13.91
Enter s,1-9,+,-,>,<,f,F,d,i,p,t,S,b,m,e,r,R,g,k,O,o,D,V,B,C,T,E,M:,l,h :

Miguel Zepeda

Post your code so we can see what triggers "error 2".

/**

  • \file FilePlayer.ino
  • \brief Example sketch of using the MP3Shield Arduino driver, with flexible list of files and formats
  • \remarks comments are implemented with Doxygen Markdown format
  • \author Bill Porter
  • \author Michael P. Flaga
  • This sketch listens for commands from a serial terminal (such as the Serial
  • Monitor in the Arduino IDE). Listening for either a single character menu
  • commands or an numeric strings of an index. Pointing to a music file, found
  • in the root of the SdCard, to be played. A list of index’s and corresponding
  • files in the root can be listed out using the ‘l’ (little L) command.
  • This sketch allows the various file formats to be played: mp3, aac, wma, wav,
  • fla & mid.
  • This sketch behaves nearly identical to MP3Shield_Library_Demo.ino, but has
  • extra complicated loop() as to recieve string of characters to create the
  • file index. As the Serial Monitor is typically default with no CR or LF, this
  • sketch uses intercharacter time out as to determine when a full string has
  • has been entered to be processed.
    */

#include <SPI.h>

//Add the SdFat Libraries
#include <SdFat.h>
#include <FreeStack.h>

//and the MP3 Shield Library
#include <SFEMP3Shield.h>

// Below is not needed if interrupt driven. Safe to remove if not using.
#if defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_Timer1
#include <TimerOne.h>
#elif defined(USE_MP3_REFILL_MEANS) && USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer
#include <SimpleTimer.h>
#endif

/**

  • \brief Object instancing the SdFat library.
  • principal object for handling all SdCard functions.
    */
    SdFat sd;

/**

  • \brief Object instancing the SFEMP3Shield library.
  • principal object for handling all the attributes, members and functions for the library.
    */
    SFEMP3Shield MP3player;
    int16_t last_ms_char; // milliseconds of last recieved character from Serial port.
    int8_t buffer_pos; // next position to recieve character from Serial port.

//------------------------------------------------------------------------------
/**

  • \brief Setup the Arduino Chip’s feature for our use.
  • After Arduino’s kernel has booted initialize basic features for this
  • application, such as Serial port and MP3player objects with .begin.
  • Along with displaying the Help Menu.
  • \note returned Error codes are typically passed up from MP3player.
  • Whicn in turns creates and initializes the SdCard objects.
  • \see
  • \ref Error_Codes
    */
    char buffer[6]; // 0-35K+null

void setup() {

uint8_t result; //result code from some function as to be tested at later time.

Serial.begin(115200);

Serial.print(F("F_CPU = "));
Serial.println(F_CPU);
Serial.print(F(“Free RAM = “)); // available in Version 1.0 F() bases the string to into Flash, to use less SRAM.
Serial.print(FreeStack(), DEC); // FreeRam() is provided by SdFatUtil.h
Serial.println(F(” Should be a base line of 1017, on ATmega328 when using INTx”));

//Initialize the SdCard.
if(!sd.begin(SD_SEL, SPI_FULL_SPEED)) sd.initErrorHalt();
// depending upon your SdCard environment, SPI_HAVE_SPEED may work better.
if(!sd.chdir("/")) sd.errorHalt(“sd.chdir”);

//Initialize the MP3 Player Shield
result = MP3player.begin();
//check result, see readme for error codes.
if(result != 0) {
Serial.print(F(“Error code: “));
Serial.print(result);
Serial.println(F(” when trying to start MP3 player”));
if( result == 6 ) {
Serial.println(F(“Warning: patch file not found, skipping.”)); // can be removed for space, if needed.
Serial.println(F(“Use the “d” command to verify SdCard can be read”)); // can be removed for space, if needed.
}
}

#if (0)
// Typically not used by most shields, hence commented out.
Serial.println(F(“Applying ADMixer patch.”));
if(MP3player.ADMixerLoad(“admxster.053”) == 0) {
Serial.println(F(“Setting ADMixer Volume.”));
MP3player.ADMixerVol(-3);
}
#endif

help();
last_ms_char = millis(); // stroke the inter character timeout.
buffer_pos = 0; // start the command string at zero length.
parse_menu(‘l’); // display the list of files to play

}

I'm using the example File player but I can't put the whole code here.

I’m using the example File player but I can’t put the whole code here.

A bit of a waste of time then as we can’t see the bit that triggers that error.

If it is example code then post a link to it, or attache the file. Read this:-
How to use this forum
It will tell you what you need to do to ask a proper question here.

here is the code attached

FilePlayer.ino (23.8 KB)

And the error message?

Error code: 2 when trying to play track
Time since last command: 13.91
Enter s,1-9,+,-,>,<,f,F,d,i,p,t,S,b,m,e,r,R,g,k,O,o,D,V,B,C,T,E,M:,l,h :

So Error code 2 while trying to play means:-

File not found

Which means you are trying to play a file that does not exist on the SD card.

Hi I’m getting the same error (Error 2) and I have double checked that my MP3 file is located on my SDCard and it is there. Here is the link to the Sparkfun MP3 Shield that both Miguel and I are using.
https://learn.sparkfun.com/tutorials/mp3-player-shield-hookup-guide-v15

Unfortunately, that sample code (File Player) runs over 9000 characters and cannot be posted here for you to view. However the error message that Miguel received in the first post matches mine. The author of the File Player code did write a simpler code to play one single track on his website, however that one has something wrong and cannot be verified. Here is the link to that website and that code.

http://www.billporter.info/2012/01/28/sparkfun-mp3-shield-arduino-library/

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

SdFat sd;
SFEMP3Shield MP3player;

void setup() {

  Serial.begin(9600);

  //start the shield
  sd.begin(SD_SEL, SPI_HALF_SPEED);
  MP3player.begin();

  //start playing track 1
  MP3player.playTrack(1);
}

//do something else now
void loop() {

  Serial.println("I'm bored!");
  delay(2000);

}

The goal is to have the one track play on the MP3 Player. I have tested the UNO and know it works, and the Sparkfun MP3 shield is lit- but as I have not had a successful test I cannot say with certainty that it does work. I have checked and renamed the file to track001.mp3 to stay with the 8.3 system this player needs. I know this code dates from 2012, as does probably the File Player code written by the same person, so I am not sure what would need to be updated. Thank you in advance for any help you can provide.

If you are getting the same error then you have the same problem, you are trying to play a file that can not be found.
So is your file in root?

Also

SdFatLib only supports 8.3 filenames. Long file names will not work. Use the 'd' menu command to display directory contents of the SdCard. "longfilename.mp3" will be converted to "longfi~1.mp3" . Where one can not predict the value of the 1. The DOS command of "dir \c /x" will list a cross reference, so that you know exactly, what is what.
Still Need Help?
Use the support forum to look for a solution or ask for help.

This is the SparkFun forum not this one.

SOLVED! I kept working at it, and when I debug the program in serial monitor I noticed this:

track001.mp3.mp3

So as Grumpy Mike pointed out, although Sparkfun/VS1053 requires the 8.3 file format, the program renders ANOTHER .mp3 file extension onto it- making the file a correct #2 error- File not found.
Corrected my changing renaming MP3 File "track001" with not extension, and the problem is solved.

Thank you Grumpy Mike!

worked for me! thanks :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: