Arduino mega2560 play an mp3 file while reading another file

My setup is built of Arduino Mega2560 with an Adafruit's Music Maker shield. I am running their "player_simple" example and listen (by earphone) to an mp3 playing in the background. That's work.

Once I try to read additional binary file from the same SD card, in parallel to listening to the music, I hear a white noise through the earphone. Also, the reading of the binary file from the SD card - fails. After resetting the Arduino couple of time (by pressing the rst button on the board), I am managing to hear the music but the reading of the binary file never happens.

Questions:

  1. I wonder what I am doing wrong? (see the code below)
  2. Is there an option to read the binary file from the SD card while playing a song (loaded on the same SD card) in the background?

Here is the relevant part of the code:

void setup{
    if (! musicPlayer.begin()) { // initialize 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(CARDCS)) {
        Serial.println(F("SD failed, or not present"));
        while (1);  // don't do anything more
    }
    // Set volume for left, right channels. lower numbers == louder volume!
    musicPlayer.setVolume(20,20);
    
    // 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 another file in the background, REQUIRES interrupts!
    musicPlayer.startPlayingFile("/e01.wav");
    
    myFile = SD.open("S1F25.bin"); // open the binary file 
    Serial.print (" myfile.read() = ");
    Serial.println (myFile.read());
    }
    void loop() {
    volume_control();
    if (musicPlayer.stopped()) {
        Serial.println("Done playing music");
        while (1) {
           delay(10);  // we're done! do nothing...
        }
    }
    delay(100);
}
    
void volume_control(){
    volume = volume + 1;
    if (volume > 90){volume = 90;}
    musicPlayer.setVolume(volume,volume);
}

This topic was automatically closed after 120 days. New replies are no longer allowed.