Issue with Adafruit Music Maker Shield (PID 1788) with Arduino Mega ADK

I have an Arduino Mega ADK and an Adafruit Music Maker Shield (PID 1788).

According to the docs, the shield can work in one of 2 ways.

Method 1: use command musicPlayer.playFullFile(“track01.mp3”) and the sketch pauses until the sound file has completely played.

Method 2: use command musicPlayer.startPlayingFile(“track01.mp3”) and now the sketch continues on processing while the file plays.

The project I am working on uses a PS-3 controller connected to the Mega via Bluetooth to control a robot. Part of the control is to signal to play audio files.

When I first got the shield, I used the example code and was able use the PS-3 controller to signal the Mega to play the file. The file would play, and I was able to continue to send signals (I was monitoring the commands being sent from the controller to the Mega on the serial monitor).

I then proceeded to try to implement more of the robot control code. And now I have now stumbled into an issue.

Now when I try to use the “startPlayingFile” command, the Mega starts to play the audio file, and just at the end, the Mega stops playing and locks up. To get the Mega to begin responding again, I close the serial monitor and re-open, and the unit is able to respond to commands, until I try to play an audio file.

Below is the stripped down version of the sketch I am starting with. Up and Right are simply used to see if the processor is still running while playing the audio file.

Left uses the “playFullFile” command. Expectedly, when I use Left, the sketch totally pauses until the audio file is done.

Down uses the “startPlayingFile”, and when the file plays, just at the end, the Mega locks up.

#include <PS3BT.h>
#include <usbhub.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7       // VS1053 chip select pin (output)
#define SHIELD_DCS    6       // VS1053 Data/command select pin (output)
#define CARDCS 4              // Card chip select pin
#define DREQ 3                // VS1053 Data request, DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DEBUG_ON

USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3(&Btd); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//============  Setup function  ============
void setup() {
  Serial.begin(9600); 

  #if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  #endif
  if (Usb.Init() == -1) {
    Serial.println(F("OSC did not start"));
    while (1); //halt
  }
  Serial.println(F("PS3 Bluetooth Library Started"));

  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("\r\nVS1053 found"));
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);
  }
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
    Serial.println(F("DREQ pin is not an interrupt pin"));
    while (1);
  }
  musicPlayer.setVolume(10,10);
  musicPlayer.playFullFile("/startup2.mp3");
}

//============  Loop function  ============
void loop() {
  Usb.Task();
  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
    if (PS3.getButtonClick(UP)){
      #ifdef DEBUG_ON
        Serial.println(F("Up"));
      #endif 
      //musicPlayer.startPlayingFile("/DP001.mp3");
    }
    if (PS3.getButtonClick(RIGHT)){
      #ifdef DEBUG_ON
        Serial.println(F("Right")); 
      #endif
      //musicPlayer.startPlayingFile("/DP002.mp3");
    } 
    if (PS3.getButtonClick(DOWN)){
      #ifdef DEBUG_ON
        Serial.println(F("Down")); 
      #endif
      musicPlayer.startPlayingFile("/R2003.mp3");
    } 
    if (PS3.getButtonClick(LEFT)){
      #ifdef DEBUG_ON
        Serial.println(F("Left")); 
      #endif
      musicPlayer.playFullFile("/DP004.mp3");
    }
    if (PS3.getButtonClick(PS)){
      #ifdef DEBUG_ON
        Serial.println(F("Disconnect Controller")); 
      #endif
      PS3.disconnect();
    }
  }
}

Has anyone had any luck resolving this issue? I have reached out to Adafruit, but I have come to learn their tech support is marginal, at best, and that takes into account if they even respond.

Thank you in advance for your help.

I close the serial monitor and re-open,

That is activating the auto reset circuit and is the same as pressing the reset button.

Did you write all this code? If so is it designed for the Mega? That includes the libraries are they compatible with the Mega? This is important because the Mega has a different timer structure than other Arduinos.

You have to find the place where it hangs, so you need to include more debug prints. I would start with going into and coming out of the library calls.

Post what you find.

Grumpy_Mike:
Did you write all this code? If so is it designed for the Mega? That includes the libraries are they compatible with the Mega? This is important because the Mega has a different timer structure than other Arduinos.

The above sketch was written for the Mega. The library is from Adafruit and specifically lists the Mega as a compatible board.

Grumpy_Mike:
You have to find the place where it hangs, so you need to include more debug prints. I would start with going into and coming out of the library calls.

Post what you find.

I have been able to add debug print lines for the actions in the sketch, and I conceptually understand what you are asking, however, I am not sure how to implement adding a debug print going into and out of a library. Is it as simple as adding:

if (PS3.getButtonClick(DOWN)){
      #ifdef DEBUG_ON
        Serial.println(F("Down"));
      #endif
      Serial.println(F("entering VS1053 Library"));
      Serial.println(F("begin playing file"));
      musicPlayer.startPlayingFile("/R2003.mp3");
      Serial.println(F("end playing file"));
      Serial.println(F("exiting VS1053 Library"));
    }

If it is, I will implement this and report, but I believe just by actions I know what the result will be. I "think" the result will be as follows:

Down
entering VS1053 Library
begin playing file

What I am not sure how to display is the fact that the audio file starts, just never finishes.

Is there a way I can add debug lines into the library to see what is going on in there? I haven't messed with actually getting into a library before, so I am not really sure how or what I can do inside the library.

Is it as simple as adding:.....

Yes.

but I believe just by actions I know what the result will be.

Good, never do a test unless you have some expectations of the result. Then you can see if you are right or not. That is the point of tests.

Is there a way I can add debug lines into the library to see what is going on in there?

Yes you canon exactly the same way. But start off with your code first.

I was finally able to get back on this project.

After many many tests, with no real results, I have decided the best course of action for this project is to add an additional processor.

I have added a Leonardo to interface to the music maker shield. That works fine. Now I am trying to get the serial data to work, but that is for another thread.