Music Maker (w/amp) : Arduino seems not to return from VS105

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Music Maker (w/amp) : Arduino seems not to return from VS105

Post by jsroques »

Hello,

I have built a kind of musix box with an Arduino MEGA, a music maker and a 4x4 button / RGB led matrix and I have some strange behavior using the startPlayingFile function.

The button matrix (4x4) allows me to chose a file (each button being associated with a file). When I press a button, it starts to play the file. If I press it again, it pauses... and if I press again, it starts again. If I press any other button, current file stops and the new one starts. So, normaly, when everything works as expected, I press a button which triggers the start of a file using startPlayingFile(). If I understand well how VS1053 and associated Adafruit lib works, startPlayingFile() feeds the buffer of the VS1053 and plays what's in the buffer and returns, then when DREQ is pulled HIGH requesting some data, VS1053 is fed again. In the meantime, the arduino runs the rest of the code (in my case, spending it refreshing the led matrix).

It mainly works but from time to time, the arduino seems to stop executing all code but the ISR function from the VS1053 Adafruit lib (namely feeder()) which calls feedBuffer().

I mean, when works as expected, when I press a button,
- startPlayingFile is called, VS1053 is fed with data from the SD card and music start
- Arduino returns from startPlayingFile() and executes the rest of the code
- then it starts a loop until the end of the file :
- - whenever DREQ triggers the interrupt, ISR function feeder() is called stopping the rest of the code, VS1053 is fed with data until DREQ is pulled LOW
- - Arduino returns from ISR call and continue to execute the code it stopped before the interrupt until next interrupt
- - loop again !

But from time to time, when I press a button, startPlayingFile is called... but seems never to come back to the place it stopped :
- startPlayingFile is called, VS1053 is fed with data from the SD card and music start
- I don't see Arduino returning from startPlayingFile() : it does not execute the rest of the code (outside ISR function)
- then it starts a loop until the end of the file :
- - whenever DREQ is triggers the interrupt, ISR function feeder() is called stopping the rest of the code, VS1053 is feed with data until DREQ is pulled LOW
- - Arduino seems not to returns from ISR call and does not continue to execute the code but will honor next interrupt !

It is still processing interrupts so it did not totally crash ! Music is actually playing but at the end of the file... Arduino is just... hung ? Waiting for something ?

I did dig a little bit in the library but I am not quite confident of my understanding of how VS1053 lib and more generaly interrupts works... So I have a few questions

I saw that the interrupt is configured to trigger on pin change. I tried to set it to RISING as VS1053 is requesting data only if DREQ is HIGH (it generates as twice as less interrupts). Seems to still work but it is not solving my problem. Is there a specific reason why interrupt is triggered on CHANGE ? What am I missing ?

Am I right when I say the Arduino code did not crash ? Or is ISR function kind of "independant" of the rest of the code ?

I noticed that when powered on a 8.4V rechargeable battery (using Vin), this is occuring much more frequently than when powered through USB. Could there be a voltage or current problem ?

Sorry for the long post... Hope I am clear...
Any help is appreciated !

And by the way : Best wishes for this new year starting !

Jean-Sébastien

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Not solved yet... but I did reproduce the problem in a much more simple way : I am playing a short file again and again, no user interaction, and it eventually stops. Here is my little program. I am using an arduino Mega.

Do I miss something obvious ?

Thanks !

Code: Select all

/*
  Debug player program
  Only looping on a single mp3 file
  
  After a (little) while, program stops. If finishes the current play but won't loop again.
  
*/

#define DEBUG_PRINTF(str,val)          \
    Serial.print(millis());            \
    Serial.print("|");                 \
    Serial.print(__PRETTY_FUNCTION__); \
    Serial.print('|');                 \
    Serial.printf(str,val);            \
    Serial.println();

#define DEBUG_PRINT(str)               \
    Serial.print(millis());            \
    Serial.print("|");                 \
    Serial.print(__PRETTY_FUNCTION__); \
    Serial.print('|');                 \
    Serial.print(str);                 \
    Serial.println();
         
#include <SPI.h>              // Needed for VS1053
#include <Adafruit_VS1053.h>  // VS1053 shield (music maker)
#include <SD.h>               // SD card library, where are stored music files

//-----------------------------------------------------------------------------------
// VS1053 shield pins
//-----------------------------------------------------------------------------------
#define VS_SHIELD_MCS    36      // VS1053 chip select pin (output)
#define VS_SHIELD_DCS    39      // VS1053 Data/command select pin (output)
#define VS_SHIELD_CCS    37      // VS1053 shield SD card chip select pin
#define VS_SHIELD_DRQ    18      // VS1053 Data request (int pin)

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS_SHIELD_MCS,VS_SHIELD_DCS,VS_SHIELD_DRQ,VS_SHIELD_CCS);  // Player
Adafruit_VS1053 VS1053 = Adafruit_VS1053(-1,VS_SHIELD_MCS,VS_SHIELD_DCS,VS_SHIELD_DRQ);  // VS1053

//=================================================================================
// SETUP
//=================================================================================
void setup() {

  Serial.begin(115200);

  DEBUG_PRINT("Starting VS1053");
  VS1053.begin();
  if (!musicPlayer.begin()) {
    DEBUG_PRINT("Couldn't find VS1053");
    while(1);
    //resetArduino();
  }

  // Initialising SD card and dumping file list
  // WARNING : This needs to be done AFTER musicPlayer.begin but BEFORE configuring music player
  //           Else we get a strange veeeerrrryyyyy slooooowwww playyyyyy
  DEBUG_PRINT("Starting SD");
  if(SD.begin(VS_SHIELD_CCS)) {
    DEBUG_PRINT("SD started");
  }
  else {
    DEBUG_PRINT("Cannot start SD");
    while(1);
  }
  
  // Configuring music player
  musicPlayer.setVolume(90, 90);   // Left and right channel volume (lower number mean louder)
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
}

//=================================================================================
// LOOP
//=================================================================================
char trackName[]="/music/12/track03.mp3";
void loop() {

  // Whenever sound stops, start it again
  if(musicPlayer.stopped()) {
      DEBUG_PRINTF("Starting %s",trackName);
      musicPlayer.startPlayingFile(trackName);  
  }
}

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Hello again,

I am kind of getting desperate here... could not find a solution.

I did add a print into the main loop() and in feeder() to my code and the VS1053 libs and get the following as it may help understand my problem :

Code: Select all


0|void setup()|Starting VS1053
602|void setup()|Starting SD
627|void setup()|SD started
628|void feeder()|DREQ!
628|void loop()|Loop...
629|void loop()|Starting /music/12/track03.mp3
734|void feeder()|DREQ!                        <=== Start feeding for the first time
735|void feeder()|DREQ!
933|void feeder()|DREQ!
933|void feeder()|DREQ!
934|void feeder()|DREQ!
935|void feeder()|DREQ!
984|void feeder()|DREQ!                        <=== Feeding end, start playing 
985|void loop()|Loop...                        <=== looping, waiting for next interrupt ~60 times
...
1095|void loop()|Loop...
1097|void feeder()|DREQ!                       <=== mp3 chip needs some data
1097|void feeder()|DREQ!
1097|void loop()|Loop...                       <=== looping, waiting for next interrupt ~60 times
...
1259|void loop()|Loop...                      
1261|void feeder()|DREQ!
1261|void feeder()|DREQ!                       <=== mp3 chip needs some data
1261|void loop()|Loop...                       <=== looping, waiting for next interrupt ~60 times
...
1386|void loop()|Loop...
1389|void feeder()|DREQ!
1389|void feeder()|DREQ!
1389|void loop()|Loop...
...
1551|void loop()|Loop...
1553|void feeder()|DREQ!
1553|void feeder()|DREQ!
1553|void loop()|Loop...
...
1626|vo1d loop()|Loop...
1628|void loop()|Starting /music/12/track03.mp3  <=== Statring to play again (previous play is finished)
1731|void feeder()|DREQ!                         <=== Start feeding for the first time
1733|void feeder()|DREQ!
1932|void feeder()|DREQ!
1932|void feeder()|DREQ!
1933|void feeder()|DREQ!
1934|void feeder()|DREQ!
1983|void feeder()|DREQ!                         <=== Feeding end, start playing 
1983|void loop()|Loop...                         <=== looping, waiting for next interrupt ~60 times 
2111|void loop()|Loop...
2113|void feeder()|DREQ!
2113|void feeder()|DREQ!
2113|void loop()|Loop...
2276|void loop()|Loop...
2278|void feeder()|DREQ!
2278|void feeder()|DREQ!
2278|void loop()|Loop...
2567|void loop()|Loop...
2570|void feeder()|DREQ!
2570|void feeder()|DREQ!
2569|void loop()|Loop...
...
2623|void loop()|Lo2p...
2626|void loop()|Starting /music/12/track03.mp3  <=== Statring to play again (previous play is finished)
2728|void feeder()|DREQ!
2729|void feeder()|DREQ!
2928|void feeder()|DREQ!
2928|void feeder()|DREQ!
2929|void feeder()|DREQ!
2930|void feeder()|DREQ!
2979|void feeder()|DREQ!
2979|void loop()|Loop...
...
3108|void loop()|Loop...
3110|void feeder()|DREQ!
3110|void feeder()|DREQ!
3110|void loop()|Loop...
...
3146|void loop()|Loop...
3148|void feeder()|DREQ!
3148|void feeder()|DREQ!
3148|void loop()|Loop...
...
3271|void loop()|Loop...
3273|void feeder()|DREQ!
3273|void feeder()|DREQ!
3273|void loop()|Loop...
3436|void loop()|Loop...
3439|void feeder()|DREQ!
3439|void feeder()|DREQ!
3438|void loop()|Loop...
...
3564|void loop()|Loop...
3566|void feeder()|DREQ!
3566|void feeder()|DREQ!
3566|void loop()|Loop...
...
3620|void loop()|L3op...
...
...       ok... you get the idea, it plays over and over until...
...
16504|void loop()|Starting /music/12/track03.mp3 <=== Statring to play again (previous play is finished)
16607|void feeder()|DREQ!                        <=== But then never returning back to the main loop
16608|void feeder()|DREQ!                        <=== although arduino did not "crash" as it is still processing interrupts (music still playing)
16807|void feeder()|DREQ!
16807|void feeder()|DREQ!
16808|void feeder()|DREQ!
16809|void feeder()|DREQ!
...
17569|void feeder()|DREQ!
17569|void feeder()|DREQ!                        <=== trigger INT ~80 time
17593|void feeder()|DREQ!                        <=== and at the end of the file, just stops (should start to play the file again)
Any help is welcome.
Thanks.
Jean-Sébastien

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by adafruit_support_mike »

Check your memory usage.

It's possible that you're hitting a condition where SRAM is corrupted to a point where the code hangs, but the interrupts force the code to skip out of the hang long enough to run the ISR.

Try calling the function from this tutorial in the ISR and see if that tells you anything useful:

https://learn.adafruit.com/memories-of- ... ree-memory

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Hello,

Thank you for your reply Mike.

I did add the the freeRam and it gives the following just before crashing

It seems there is no leak and no shortage of memory.
But, (I did not noticed in the first place) when it fails, it seems to use a bit more memory, although is start with the same amout :

Code: Select all

Starting VS1053Starting SDSD startedISR|0|freeRAM:6970
Loop|1|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|1|freeRAM:6956
ISR|1|freeRAM:6970
ISR|1|freeRAM:6970
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6942
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6942
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6942
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6936
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
ISR|1|freeRAM:6939
Loop|2|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|2|freeRAM:6953
...
ISR|2|freeRAM:6942
Loop|3|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|3|freeRAM:6956
...
ISR|3|freeRAM:6939
Loop|4|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|4|freeRAM:6953
...
ISR|4|freeRAM:6936
Loop|5|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|5|freeRAM:6956
...
ISR|5|freeRAM:6936
...
...
Loop|17|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|17|freeRAM:6956
ISR|17|freeRAM:6970
ISR|17|freeRAM:6970
ISR|17|freeRAM:6939
ISR|17|freeRAM:6942
ISR|17|freeRAM:6936
ISR|17|freeRAM:6942
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6942
ISR|17|freeRAM:6939
ISR|17|freeRAM:6942
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6942
ISR|17|freeRAM:6936
ISR|17|freeRAM:6936
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6936
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6936
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6939
ISR|17|freeRAM:6942
ISR|17|freeRAM:6939
Loop|18|Starting:/music/12/track03.mp3|freeRAM:6992
ISR|18|freeRAM:6953
ISR|18|freeRAM:6970
ISR|18|freeRAM:6970
ISR|18|freeRAM:6851    <== HERE, "lost" more than 100 bytes 
ISR|18|freeRAM:6851    <== and then not varying from a single byte
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
ISR|18|freeRAM:6851
Could this come from a hardware problem ? I mean, in provided voltages ?
It seems to happen more frequently whan power supply voltage is higher. I mean,
  • when connected only to USB, it barely happens.
    when connected to a 8.4 rechargeable battery, it happens quite frequently for a while, I guess while the voltage is high enough
    when connected to a 9V to 12V power supply, it happens quite frequently (it run for less than a 100 times).
Thank you in anticipation the your help.
Jean-Sébastien.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by adafruit_support_mike »

I wouldn't expect a connection between supply voltage and error rates, but if you're seeing one that's probably a clue.

Post a photo of your hardware and connections and we'll take a look.

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Here is a photo...
Image
but I guess it is not that helpful ;-)

So I attached a PNG with the schematic (could not post the original Fritzing file).

Also, I did some other tests : I disconnected everything and connected only the music maker... and seems like the problem disapeared. So it makes me believe that there is something wrong with my circuit.

Here is a simple schematic of the Arduino MEGA pins I used to connect the music maker :
Image
Jean-Sébastien
Attachments
NoeJukeBox v7b_schem.png
NoeJukeBox v7b_schem.png (449.16 KiB) Viewed 781 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by adafruit_support_mike »

That's a nice build, and the three images make almost perfect documentation for the circuit.

Schematics give you a map of a circuit, but hardware photos tell you what's actually there. At the physics level electronics is all about 3d geometry, so knowing how close the wires are to each other can be as important as knowing where their ends should be.

In this case, it sounds like you may be running into the current limits of your power supplies. I see that your 8.4v rechargeable has the same package as a 9v battery, and those tend to have trouble putting out more more 500mA. If you have speakers and an LED array, there are probably cases where your circuit could want 1A or more.

Try giving the Music Maker and LED array separate power supplies.

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Hello again,

I didn't get enough time to do much more testing as of now... but I will !
My little nephew is waiting for his music box since christmas :-( So I want to get this working reliably !

In my test sketch, I only make use of the mp3 player. l am not switching any led on. So I tend to think it is not a current issue.

Nevertheless, I am more of an IT guy than an electronic guy... So I will take your suggestion into account and try measure how much the circuit consume when everything is switched on so I make sure I got proper power supply. I may go for a 3.6V Lipo battery and connect it to 5V (using a step up circuit) and not use Vin. Would that be better ?

Thank you for your help
Jean-Sébastien.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by adafruit_support_mike »

A LiPo with a booster would be a good choice.

We have the PowerBoost 500 and 1000 over in the shop:

https://www.adafruit.com/products/1903
https://www.adafruit.com/products/2030

Either one should be able to deliver 1A from a suitably-sized LiPo.

The PowerBoost boards pull about 1.5A @ 3.7v from the LiPo for every 1A @ 5v they deliver to the load, so you want a LiPo that's comfortable providing that much current. Our smaller LiPo packs are designed for 0.5C discharge, where 'C' is the current level that will discharge the cell in 1 hour. For a 2500mAh cell, 1C=2.5A and 0.5C=1250mA, which is about as low as you'd probably want to go.

We have larger LiPo packs made for higher-power applications, so they're rated for a 2C discharge rate. The 2200mAh pack there can put out 4.4A if necessary. Running it at 1.5A would be no trouble at all. We also have 4400mAh and 6600mAh packs:

https://www.adafruit.com/products/1781
https://www.adafruit.com/products/354
https://www.adafruit.com/products/353

User avatar
jsroques
 
Posts: 24
Joined: Tue Apr 08, 2014 5:37 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by jsroques »

Hello Mike,

I just wanted to let you know that my issue seems solved.

I used the lastest version of the Adafruit library which included 2 additions which may be the cure (the one I used was quite old... I should have looked) :
  • Prevent feedBuffer from interrupting itself
  • add cancel and resync
I believe that the first one is the best guess.
If I find the time I will test my gizmo without those corrections to confirm. But for now, it works like a charm :-)

So you were right : nothing to do with powering... I am still thinking about using LiPo battery though as it works for around 30 minutes with 9V battery...

You can see it in action here : http://interactingobjects.com/category/ ... sound-box/

Thank you for the time spent helping and also for Music Maker and associated library !
Jean-Sébastien

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Music Maker (w/amp) : Arduino seems not to return from V

Post by adafruit_support_mike »

Glad to hear it's working for you. Happy hacking!

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

Return to “Arduino Shields from Adafruit”