VS1053 Shield Power OFF

Hello, Sir.

I am trying to create functions for recording and playing MP3 files. I am using an Arduino Uno with a VS1053 shield. However, when I try to play a recorded MP3 from the SD card using the VS1053 shield, it doesn’t work.

This is my code. *********************************************************

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

SdFat sd;
SFEMP3Shield MP3player;

const char* TARGET_FILE = "1.mp3"; 
char actualFileName[13]; // Variables to store file names found in real SD
bool fileFound = false;

byte volumeState = 30;
#define VOLUME_PIN A0

// [Add] A function that lists all the files on the SD card and checks if you have TARGET_FILE
void listAndFindFile() {
  SdFile root;
  SdFile entry;
  root.open("/");

  Serial.println(F("--- [SD Card File List] ---"));
  
  while (entry.openNext(&root, O_RDONLY)) {
    char name[13];
    entry.getName(name, sizeof(name));
    Serial.print(F("File found: ")); 
    Serial.println(name);

    // Find the name
    if (strcasecmp(name, TARGET_FILE) == 0) {
      strcpy(actualFileName, name);
      fileFound = true;
    }
    entry.close();
  }
  
  Serial.println(F("---------------------------"));
  if (fileFound) {
    Serial.print(F("Match Found! Using file: "));
    Serial.println(actualFileName);
  } else {
    Serial.println(F("ERROR: Target file NOT FOUND on SD card."));
  }
  root.close();
}

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("Initializing SD & MP3 Shield..."));

  // 1. Init SD card
  if (!sd.begin(9, SPI_HALF_SPEED)) {
    Serial.println(F("SD initialization failed!"));
    sd.initErrorPrint();
    while (1);
  }
  Serial.println(F("SD Card OK."));

  // 2. Print File List
  listAndFindFile();

  if (!fileFound) {
    Serial.println(F("Please check your SD card and restart."));
    while (1); // 파일을 못 찾으면 여기서 중단
  }

  // 3. Init MP3 Player
  uint8_t result = MP3player.begin();
  if (result != 0) {
    Serial.print(F("VS1053 Error Code: "));
    Serial.println(result);
    while (1);
  }
  Serial.println(F("VS1053 OK."));

  MP3player.setVolume(volumeState, volumeState);

  // 4. Play with a founded record.
  result = MP3player.playMP3(actualFileName);
  if (result != 0) {
    Serial.print(F("Play Error: "));
    Serial.println(result);
  }
}

void loop() {
  // When the song is over, repeat it
  if (!MP3player.isPlaying()) {
    MP3player.playMP3(actualFileName);
  }

  // Control Volume
  static uint32_t lastVolTime = 0;
  if (millis() - lastVolTime > 200) {
    int potValue = analogRead(VOLUME_PIN);
    byte newVol = map(potValue, 0, 1023, 10, 100);
    
    if (abs(newVol - volumeState) > 2) {
      volumeState = newVol;
      MP3player.setVolume(volumeState, volumeState);
    }
    lastVolTime = millis();
  }
}

This is the result **************************************************

17:19:15.505 -> --- [SD Card File List] ---

17:19:15.537 -> File found: System Volum

17:19:15.569 -> File found: 1.mp3

17:19:15.569 -> File found: 2.mp3

17:19:15.601 -> File found: 3.mp3

17:19:15.633 -> File found: 4.mp3

17:19:15.633 -> ---------------------------

17:19:15.666 -> Match Found! Using file: 1.mp3

17:19:15.881 -> VS1053 Error Code: 6.

I also use SFEMP3SHIELD FilePlayer Example. But it also not working when I choose the mp3. How can I solve this problem.

Please correct your post and add code tags around your code.

There is a small pencil image below your existing post.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

Thank you, sir.

can you verify your SPI connections and pins ? (Is the shield correctly plugged in ?)

Can you also try powering the UNO from a 9V DC adapter or USB from your computer and remove the battery pack

The errorcode 6 means that you didn't load .plugins files to your SdCard as described in

For more info see the "installation" and " Plug Ins and Patches" sections of the guide.

This error means that the shield cannot read the SD card. VS1053 MP3 Shield Not Reading SD Card

Is not the case. The output of the code shows a list of the files, so that there are no problem with SD reading.

Take note, that OP used a SFEMP3Shield class in his code. It has a different errorcodes. See the source

is your VS1053 shield a clone or an original SparkFun MP3 Player Shield or Seeduino MP3 Player Shield ?

@shallsus23 I have a shield that looks like yours in every way and I once used it with the Adafruit library. The Adafruit library example was written for their VS1053 breakout module and I reassigned the pins to match the Arduino UNO.

If you try this use a SD card of 32GB or less and remove the large capacitor and battery pack, at least until you know it works. I have not used this for a long time but it appears I used filenames like 001.mp3 , 002.mp3 etc.


// mp3 file seek function discussion
//  https://forums.adafruit.com/viewtopic.php?t=123646v

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
#define CLK 13       // SPI Clock, shared with SD card
#define MISO 12      // Input data, from VS1053/SD card
#define MOSI 11      // Output data, to VS1053/SD card
#define CS 9     // SD Card chip select pin
// Connect CLK, MISO and MOSI to hardware SPI pins. 

// These are the pins used for the music maker shield
#define X_RESET  8      // VS1053 reset pin (unused!)
#define X_DCS    7      // VS1053 Data/command select pin (output)
#define X_CS     6      // VS1053 chip select pin (output)

// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 2       // VS1053 Data request, ideally an Interrupt pin

int old_adc = 0;
bool test = false;
Adafruit_VS1053_FilePlayer musicPlayer = 
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(X_RESET, X_CS, X_DCS, DREQ, CS);
  
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
  
   if (!SD.begin(CS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // list files
  printDirectory(SD.open("/"), 0);
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(10,10);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  // Play one file, don't return until complete
  //Serial.println(F("Playing track 001"));
  //musicPlayer.playFullFile("/001.mp3");
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing track 001"));
 
  musicPlayer.startPlayingFile("/001.mp3",400000);
  uint32_t val =    musicPlayer.getFilePosition();
  Serial.println(val);
 
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1) {
      delay(10);  // we're done! do nothing...
    }
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
  int adc  = analogRead(0) ; 	 //reading analog voltage and storing it in an integer 
  adc = map(adc, 0, 1023, 0, 65);
  if (old_adc != adc){old_adc = adc;}// Serial.println(adc);}
  //musicPlayer.setVolume(adc,adc); 
  musicPlayer.setVolume(10,10); 
}


/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
       
     }
     entry.close();
   }
 
}



Thank you to apply my question, sir.
But when I use your code

// mp3 file seek function discussion
//  https://forums.adafruit.com/viewtopic.php?t=123646v

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
#define CLK 13       // SPI Clock, shared with SD card
#define MISO 12      // Input data, from VS1053/SD card
#define MOSI 11      // Output data, to VS1053/SD card
#define CS 9     // SD Card chip select pin
// Connect CLK, MISO and MOSI to hardware SPI pins. 

// These are the pins used for the music maker shield
#define X_RESET  8      // VS1053 reset pin (unused!)
#define X_DCS    7      // VS1053 Data/command select pin (output)
#define X_CS     6      // VS1053 chip select pin (output)

// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 2       // VS1053 Data request, ideally an Interrupt pin

int old_adc = 0;
bool test = false;
Adafruit_VS1053_FilePlayer musicPlayer = 
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(X_RESET, X_CS, X_DCS, DREQ, CS);
  
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
  
   if (!SD.begin(CS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // list files
  printDirectory(SD.open("/"), 0);
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(10,10);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  // Play one file, don't return until complete
  //Serial.println(F("Playing track 001"));
  //musicPlayer.playFullFile("/001.mp3");
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing track 001"));
 
  musicPlayer.startPlayingFile("/001.mp3",400000);
  uint32_t val =    musicPlayer.getFilePosition();
  Serial.println(val);
 
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1) {
      delay(10);  // we're done! do nothing...
    }
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
  int adc  = analogRead(0) ;     //reading analog voltage and storing it in an integer 
  adc = map(adc, 0, 1023, 0, 65);
  if (old_adc != adc){old_adc = adc;}// Serial.println(adc);}
  //musicPlayer.setVolume(adc,adc); 
  musicPlayer.setVolume(10,10); 
}


/// File listing helper
void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
       
     }
     entry.close();
   }
 
}

The result is

C:\Users\USER\AppData\Local\Temp\.arduinoIDE-unsaved20251122-20432-wue2j6.98bmk\sketch_dec22a\sketch_dec22a.ino:64:49: error: no matching function for call to 'Adafruit_VS1053_FilePlayer::startPlayingFile(const char [9], long int)'
   musicPlayer.startPlayingFile("/001.mp3",400000);
                                                 ^
In file included from C:\Users\USER\AppData\Local\Temp\.arduinoIDE-unsaved20251122-20432-wue2j6.98bmk\sketch_dec22a\sketch_dec22a.ino:6:0:
c:\Users\USER\Documents\Arduino\libraries\Adafruit_VS1053_Library/Adafruit_VS1053.h:378:11: note: candidate: boolean Adafruit_VS1053_FilePlayer::startPlayingFile(const char*)
   boolean startPlayingFile(const char *trackname);
           ^~~~~~~~~~~~~~~~
c:\Users\USER\Documents\Arduino\libraries\Adafruit_VS1053_Library/Adafruit_VS1053.h:378:11: note:   candidate expects 1 argument, 2 provided
C:\Users\USER\AppData\Local\Temp\.arduinoIDE-unsaved20251122-20432-wue2j6.98bmk\sketch_dec22a\sketch_dec22a.ino:65:33: error: 'class Adafruit_VS1053_FilePlayer' has no member named 'getFilePosition'
   uint32_t val =    musicPlayer.getFilePosition();
                                 ^~~~~~~~~~~~~~~
Multiple libraries were found for "SD.h"
  Used: C:\Users\USER\Documents\Arduino\libraries\SD
  Not used: C:\Users\USER\AppData\Local\Arduino15\libraries\SD
exit status 1

Compilation error: no matching function for call to 'Adafruit_VS1053_FilePlayer::startPlayingFile(const char [9], long int)'`

Could you give the me about the informations about the library version?