Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Music player shield will no play with musicPlayer.startPlayi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Music player shield will no play with musicPlayer.startPlayi

by WiggyG on Sat Mar 21, 2020 6:19 pm

Hi to all at Adafruit. I bought a music player shield and Arduino UNO to build a talking model rocket launcher for my niece. After getting spurious results, I reflowed all my solder joints and wrote a simplified sketch to see if I could find the problem independent of any button/LED connections. Connected to only a speaker, it seems the audio will play using the "musicPlayer.playFullFile" command but not the "musicPlayer.startPlayingFile" command. I tried using a fresh Arduino UNO and got the same results. Searching the forum I found a suggestion that I downgrade from SD library 1.2.4 to 1.0.9. This didn't help, so I switched back to 1.2.4. Using the sketch below, the player plays abort1, countdwn, and liftoff with no problem; serial monitor then displays "starting to play abort1 now", and the speaker makes a sound like it's about to play the abort1 file again and then stops and goes into an endless loop of "should be playing abort1 now but nothing is playing and this line prints in endless loop" on the serial monitor. I apologize as I am sure I've done something stupid, but I am out of ideas.
Code: Select all | TOGGLE FULL SIZE
// include SPI, MP3 and SD libraries for Adafruit_VS1053 music player
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the music maker shield
#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, ideally an Interrupt pin


Adafruit_VS1053_FilePlayer musicPlayer =
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);   //create shield object

void setup() {
  Serial.begin(9600);
  musicPlayer.begin();
  SD.begin(CARDCS);

}


void loop() {

  musicPlayer.setVolume(40, 40);
  musicPlayer.playFullFile("/abort1.mp3");

  musicPlayer.setVolume(70, 70);
  musicPlayer.playFullFile("/countdwn.mp3");


  musicPlayer.setVolume(40, 40);
  musicPlayer.playFullFile("/liftoff.mp3");


  musicPlayer.setVolume(40, 40);
  musicPlayer.startPlayingFile("/abort1.mp3");
  Serial.println("starting to play abort1 now");
  while (musicPlayer.playingMusic) {
    Serial.println("should be playing abort1 now but nothing is playing and this line prints in endless loop");
    delay(100);
  }
  Serial.println("just finished playing abort1 now");
  musicPlayer.setVolume(20, 20);
  Serial.println("should be starting to play liftoff now");
  musicPlayer.playFullFile("/liftoff.mp3");

}

WiggyG
 
Posts: 5
Joined: Sat Mar 21, 2020 5:57 pm

Re: Music player shield will no play with musicPlayer.startP

by jim_lee on Mon Mar 23, 2020 6:04 pm

Try commenting this out.

Code: Select all | TOGGLE FULL SIZE
 while (musicPlayer.playingMusic) {
    Serial.println("should be playing abort1 now but nothing is playing and this line prints in endless loop");
    delay(100);
  }


-jim lee

jim_lee
 
Posts: 648
Joined: Thu May 24, 2012 8:24 pm

Re: Music player shield will no play with musicPlayer.startP

by WiggyG on Mon Mar 23, 2020 8:38 pm

Hi Jim,
Thanks for looking at my problem. I commented out the area that you suggested, and the shield played all of abort1, countdwn, and liftoff as expected; it did not play the abort1 with the musicPlayer.startPlayingFile command, and proceeded directly to playing "liftoff" a second time (using the playFullFile command) and then started back at the beginning of the void loop() again.
Thanks,
John

WiggyG
 
Posts: 5
Joined: Sat Mar 21, 2020 5:57 pm

Re: Music player shield will no play with musicPlayer.startP

by jim_lee on Tue Mar 24, 2020 4:21 pm

You are very welcome! Glad I could help. Many times I just make the issues worse for people. :)

-jim lee

jim_lee
 
Posts: 648
Joined: Thu May 24, 2012 8:24 pm

Re: Music player shield will no play with musicPlayer.startP

by WiggyG on Tue Mar 24, 2020 4:32 pm

Well actually, I'm still stuck with the same problem. I can play the entirety of an audio file using the musicPlayer.playFullFile() command, but while the audio is running, no other processes can be performed (such as checking for button presses). In order to play a file and perform other processes while the file is playing, I need to use the musicPlayer.startPlayingFile() command, which I can't get to work.
Any ideas out there in Adafruit land?
Thanks,
John

WiggyG
 
Posts: 5
Joined: Sat Mar 21, 2020 5:57 pm

Re: Music player shield will no play with musicPlayer.startP

by jim_lee on Tue Mar 24, 2020 7:58 pm

There is a way..

a) NO delay() calls!
b) In your main loop() at the top add this:
Code: Select all | TOGGLE FULL SIZE
if (musicPlayer->playingMusic) {
   musicPlayer->feedBuffer();
}


c) To start it you will need a call like this :
Code: Select all | TOGGLE FULL SIZE
imusicPlayer->startPlayingFile(filePath);


d) Maybe do the startPlaying call in setup on a long song, then during the loop() check to see if the buttons are being picked up.

No guarantees but this is basically the way I do it. (I hate using interrupts. Its always a turf war with other hardware.)

-jim lee

jim_lee
 
Posts: 648
Joined: Thu May 24, 2012 8:24 pm

Re: Music player shield will no play with musicPlayer.startP

by WiggyG on Tue Mar 24, 2020 8:47 pm

but why doesn't the "musicPlayer.startPlayingFile" command work at all?

WiggyG
 
Posts: 5
Joined: Sat Mar 21, 2020 5:57 pm

Re: Music player shield will no play with musicPlayer.startP

by jim_lee on Wed Mar 25, 2020 12:19 am

I don't know.

But I do know, you have to give about 99% of the processor time to filling the file buffer doing the music in the background like you want. You can do -very little- between file filling hits. I see in my code 40 ms is the interval I'm using for file filing hits. In the code I saw you post you had delay()s in there. Those are the equivalent of "Go have a smoke for 5,000 years then check back".

Did you try start playing file using my file feeding call?

-jim lee

jim_lee
 
Posts: 648
Joined: Thu May 24, 2012 8:24 pm

Re: Music player shield will no play with musicPlayer.startP

by WiggyG on Wed Mar 25, 2020 9:04 pm

Well, I got my hands on a second music shield and had the same problem. Finally figured out that I was missing the call for the interrupt: musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);

Now it will allow me to use the musicPlayer.startPlaying command, but only if I comment out the first two uses of musicPlayer.playFullFile("/liftoff.mp3");

Code: Select all | TOGGLE FULL SIZE

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

// These are the pins used for the music maker shield
#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, ideally an Interrupt pin


Adafruit_VS1053_FilePlayer musicPlayer =
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);   //create shield object

void setup() {
  Serial.begin(9600);                           
  musicPlayer.begin();
  SD.begin(CARDCS);
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);


}


void loop() {

  /*musicPlayer.setVolume(40, 40);
  musicPlayer.playFullFile("/abort1.mp3");

  musicPlayer.setVolume(70, 70);
  musicPlayer.playFullFile("/countdwn.mp3");*/


  musicPlayer.setVolume(40, 40);
  musicPlayer.playFullFile("/liftoff.mp3");


  musicPlayer.setVolume(40, 40);
  musicPlayer.startPlayingFile("/abort1.mp3");
  Serial.println("starting to play abort1 now");
  while (musicPlayer.playingMusic) {
    Serial.println("playing abort1 now");
   
  }
  Serial.println("just finished playing abort1 now");
  musicPlayer.setVolume(20, 20);
  Serial.println("should be starting to play liftoff now");
  musicPlayer.playFullFile("/liftoff.mp3");

}



This had me wondering if it could be a memory issue, so I did a different sketch using freeMemory(), but this also did not seem to be the problem.

At least now I can use the musicPlayer.startPlaying command, which is a step in the right direction.

WiggyG
 
Posts: 5
Joined: Sat Mar 21, 2020 5:57 pm

Please be positive and constructive with your questions and comments.