VS1053 Music Player bug?

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fxmech
 
Posts: 90
Joined: Fri Mar 09, 2012 12:19 pm

VS1053 Music Player bug?

Post by fxmech »

I was having lots of problems with this board.
I needed to run a long MP3 and cut it of with another MP3 when a trigger was hit.
I did the long MP3 using musicPlayer.startPlayingFile("Breath0.mp3");
and then cut it off on cue with
musicPlayer.stopPlaying();
musicPlayer.playFullFile("Stomach1.mp3");

It worked great a few times but then always locked up when I pressed the triggers.

I decided to try a delay and that fixed the problem.

I used a delay(50); but maybe it can be even smaller, just seems like the musicPlayer.stopPlaying();
function needs a little bit of time to finish what it does....

musicPlayer.stopPlaying();
delay(50);
musicPlayer.playFullFile("Stomach1.mp3");

FULL CODE:
//based on Adafruit VS1053 example file

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// These are the pins used for the music maker shield
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = 
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

const int buttonPin[5] = {
  10,2,5,8,9};    // the number of the pushbutton pin
int reading[5];
int rnd;

void setup() {
  Serial.begin(9600);
  // set up serial port
  musicPlayer.begin();
  SD.begin(CARDCS);    // initialise the SD card
  musicPlayer.setVolume(0,0);
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  for (int q=1;q<5;q++)pinMode(buttonPin[q], INPUT_PULLUP);
}

void loop() {
  if (musicPlayer.stopped()) {
    rnd=random(2);
    if (rnd==0){
      musicPlayer.startPlayingFile("Breath0.mp3"); 
    }
    else
      if (rnd==1){
        musicPlayer.startPlayingFile("Breath1.mp3"); 
      }
  }         
  for (int q=1;q<5;q++) {
    reading[q] = digitalRead(buttonPin[q]);
    if (reading[q]==LOW){
      switch(q){

      case 2: //button 1
        rnd=random(3);
        if (rnd==0){
          musicPlayer.stopPlaying();
          delay(50);
          musicPlayer.playFullFile("Stomach0.mp3"); 
        }
        else
          if (rnd==1){
            musicPlayer.stopPlaying();
            delay(50);
            musicPlayer.playFullFile("Stomach1.mp3");
          } 
          else
            if (rnd==2){
              musicPlayer.stopPlaying();
              delay(50);
              musicPlayer.playFullFile("Stomach2.mp3");
            }
        break;

      case 1://button 2
        rnd=random(4);
        if (rnd==0)       {
          musicPlayer.stopPlaying();
          delay(50);
          musicPlayer.playFullFile("Fart0.mp3"); 
        }
        else
          if (rnd==1){
            musicPlayer.stopPlaying();
            delay(50);
            musicPlayer.playFullFile("Fart1.mp3"); 
          }
          else
            if (rnd==2){
              musicPlayer.stopPlaying();
              delay(50);
              musicPlayer.playFullFile("Fart2.mp3"); 
            }
            else
              if (rnd==3){
                musicPlayer.stopPlaying();
                delay(50);
                musicPlayer.playFullFile("Fart3.mp3");
              }
        break;

      case 4://button 3
        rnd=random(3);
        if (rnd==0){
          musicPlayer.stopPlaying();
          delay(50);
          musicPlayer.playFullFile("Fart4.mp3"); 
        }
        else
          if (rnd==1){
            musicPlayer.stopPlaying();
            delay(50);
            musicPlayer.playFullFile("Fart5.mp3"); 
          }
          else
            if (rnd==2){
              musicPlayer.stopPlaying();
              delay(50);
              musicPlayer.playFullFile("Fart6.mp3");
            }
        break;
      }
    }
  } 
}





Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”