0

AdaFruit Music Maker MP3 Shield Troubleshooting Interrupt al
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AdaFruit Music Maker MP3 Shield Troubleshooting Interrupt al

by rao102 on Mon Nov 03, 2014 12:40 pm

The code I am using is based off the player_simple library code. I want to be able to interrupt all three songs via serial port, however I am only able to interrupt the last song. I declared all three songs to startplayingFile but when uploading the code and checking the serial port, it plays through all 3 songs in a second and displays "Done Playing Music". I had to reformat the first two files to playFullFile and leave the last one to startplayingFile.

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

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

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// 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 breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  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("VS1053 found"));
 
  SD.begin(CARDCS);    // initialise the SD card
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(5,5);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // 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 one file, don't return until complete
  Serial.println(F("Playing sample1"));
  musicPlayer.playFullFile("sample1.mp3");
 
  Serial.println(F("Playing sample2"));
  musicPlayer.playFullFile("sample2.mp3");
 
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing sample3"));
  musicPlayer.startPlayingFile("sample3.mp3");

}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
   
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
   
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else {
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}
Last edited by rao102 on Mon Nov 03, 2014 1:17 pm, edited 2 times in total.

rao102
 
Posts: 14
Joined: Mon Nov 03, 2014 12:29 pm

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by adafruit_support_bill on Mon Nov 03, 2014 12:58 pm

I had to reformat the first two files to playFullFile and leave the last one to startplayingFile.

playFullFile is a blocking call. The code will not be checking the serial port until the file is done.

You need to call startPlayingFile and check the serial port while it is playing.

adafruit_support_bill
 
Posts: 67906
Joined: Sat Feb 07, 2009 10:11 am

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by rao102 on Mon Nov 03, 2014 1:21 pm

I should of been more specific with my problem, I have declared all three files to startplayingFile in the past and when I run the program and check the serial port, it will display playing all three files in a second and then display done playing music.

rao102
 
Posts: 14
Joined: Mon Nov 03, 2014 12:29 pm

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by adafruit_support_bill on Mon Nov 03, 2014 1:33 pm

Post the code you were using. You need to wait for the first one to finish before starting the next one.

adafruit_support_bill
 
Posts: 67906
Joined: Sat Feb 07, 2009 10:11 am

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by rao102 on Mon Nov 03, 2014 2:08 pm

Here is the code for when I declared all three to startPlayingFile in hopes of being able to interrupt all three

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

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

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// 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 breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  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("VS1053 found"));
 
  SD.begin(CARDCS);    // initialise the SD card
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(5,5);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // 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 one file, don't return until complete
  Serial.println(F("Playing sample1"));
  musicPlayer.startPlayingFile("sample1.mp3"); //naming all 3 to startPlayingFile
 
  Serial.println(F("Playing sample2"));
  musicPlayer.startPlayingFile("sample2.mp3");
 
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing sample3"));
  musicPlayer.startPlayingFile("sample3.mp3");

}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
   
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
   
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else {
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}
Last edited by adafruit_support_bill on Mon Nov 03, 2014 2:12 pm, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

rao102
 
Posts: 14
Joined: Mon Nov 03, 2014 12:29 pm

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by adafruit_support_bill on Mon Nov 03, 2014 2:18 pm

Please use code tags when posting code to the forums.

Despite the comment, startPlayingFile will return immediately. You need to wait until it has completed before starting the next one.
Code: Select all | TOGGLE FULL SIZE
  // Play one file, don't return until complete
  Serial.println(F("Playing sample1"));
  musicPlayer.startPlayingFile("sample1.mp3"); //naming all 3 to startPlayingFile
 
  Serial.println(F("Playing sample2"));
  musicPlayer.startPlayingFile("sample2.mp3");
 
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing sample3"));
  musicPlayer.startPlayingFile("sample3.mp3");

If you want all of them to be interruptable, you need to do your waiting in the loop() function where you are checking the serial input.
Create a variable to remember which track is playing and when the first on completes, start the second one.

adafruit_support_bill
 
Posts: 67906
Joined: Sat Feb 07, 2009 10:11 am

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by rao102 on Thu Nov 06, 2014 12:04 pm

I have created a list for being able to go though all the songs and made a while loop to go through the list of files using a count increment. The new while loop is created just before the loop(), when running it and checking the serial port it will still go through the first two songs in a second but then play the last one fine and I am still able to interrupt it. Could there be something wrong with my while loop?

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

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

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// 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 breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
   
     char *names[3]={"sample 1", "sample 2", "sample 3"};
     char *files[3]={"sample1.mp3", "sample2.mp3", "sample3.mp3"};
 
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  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("VS1053 found"));
 
  SD.begin(CARDCS);    // initialise the SD card
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(5,5);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // 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 one file, don't return until complete
  Serial.println(F("Playing sample1"));
  musicPlayer.playFullFile("sample1.mp3");
 
  Serial.println(F("Playing sample2"));
  musicPlayer.playFullFile("sample2.mp3");
 
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing sample3"));
  musicPlayer.startPlayingFile("sample3.mp3");

*/
  int count = 0;
 
  while (count != 3){
   
    Serial.print("Playing ");
    Serial.println(names[count]);
    musicPlayer.startPlayingFile(files[count]);
    loop();
    count ++ ;
  }

}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1);
  }
 
  // else{
   
   
   
  if (Serial.available()) {
    char c = Serial.read();
   
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
   
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else {
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }
 //}
  delay(100);
}

rao102
 
Posts: 14
Joined: Mon Nov 03, 2014 12:29 pm

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by adafruit_support_bill on Thu Nov 06, 2014 1:31 pm

You are trying to play them all in setup. You need to do it in the loop:

Code: Select all | TOGGLE FULL SIZE
 
int count = 0;

void loop()
{
    if (musicPlayer.stopped() && count < 3) // nothing is playing - start a track:
    {
        Serial.print("Playing ");
        Serial.println(names[count]);
        musicPlayer.startPlayingFile(files[count]);
        count ++ ;  // increment the count for next time
    }
}

adafruit_support_bill
 
Posts: 67906
Joined: Sat Feb 07, 2009 10:11 am

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by rao102 on Thu Nov 06, 2014 2:20 pm

I went ahead and reformatted the while() like this and it seems to be working, I'll go ahead and try your suggestion anyway. Thanks.

Code: Select all | TOGGLE FULL SIZE
  while (count < 3){
   
    Serial.print("Playing ");
    Serial.println(names[count]);
    musicPlayer.startPlayingFile(files[count]);
   
    while (! musicPlayer.stopped()){
    loop();
    }
    count ++ ;
   
  }

rao102
 
Posts: 14
Joined: Mon Nov 03, 2014 12:29 pm

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by rpechler on Sun Apr 26, 2015 4:18 am

Hi,

I didn't find a option to add an new issue on this board. I have an pin conflict between the gameduino 2 and the music maker mp3 shield from adafruit.
Can somebody help me to solve this problem?

Maybe it is possible to reroute some pins of the music maker mp3 shield.
I don't no what to do.

Please help.

Regards, Reinier

rpechler
 
Posts: 4
Joined: Sun Apr 26, 2015 3:39 am

Re: AdaFruit Music Maker MP3 Shield Troubleshooting Interrup

by adafruit_support_bill on Sun Apr 26, 2015 6:48 am

I didn't find a option to add an new issue on this board.


If you go to the top of the "Arduino Shields" forum page, there is a button on the upper left labeled "Post A Topic". This will create a new thread for your question.
viewforum.php?f=31

adafruit_support_bill
 
Posts: 67906
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.