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.