Pages: [1]   Go Down
Author Topic: sparkfun mp3 shield crash  (Read 1266 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'm building my very first arduino project and what I want it to do is to use a potentiometer (attached to A5) to select mp3 tracks on a SD card using the sparkfun mp3 shield  and play them back.  I have the difficult stuff figured out (I think), I can get the audio to play, and I can even get the tracks to change a few times, but that is when it starts running into problems.  I have the serial monitor running as well for debugging purposes and every time, after changing the tracks a few times either the serial monitor crashes and stops updating it's values, and the mp3 track keeps playing (but won't start a new track) or that both the serial monitor stops updating and the mp3 stops playing.  The other odd thing it is doing is I have 5 mp3's it should be selecting, however it seems to be assigning tracks at random (i.e. sometimes when it should be selecting track 1 it actually plays track 3). I'm using a library provided by this guy http://www.billporter.info/sparkfun-mp3-shield-arduino-library/ who has made my life a lot easier, but I'm not sure if something is messing up behind the scenes.  I wouldn't know what to look for if it was.  The code for the project is below.  I've started using volatile Int's because I was hoping that was the problem.  I'm not sure if they all need to be volatile.  I've even commented out the serial monitoring in case that was causing a conflict somehow but that didn't help.  The delay is in there for the same reason.  Anyway, any help would be appreciated, it is probably something very obvious that I am missing.  I've been teaching myself how to code so I'm sure there are holes in my education.

Thanks!

Code:

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>

SFEMP3Shield MP3player;


int potPin = A5;


void setup (){

  pinMode (potPin, INPUT);
  MP3player.begin();
  MP3player.SetVolume(1, 1);
  Serial.begin(9600);
 
 
}

 boolean checkMovement (int oldPinValue){
  volatile int currentValue = analogRead(potPin);
  currentValue = constrain(currentValue, 0, 1000);
  volatile int val = map (currentValue, 0, 1000, 1, 5);
  if (oldPinValue == val){
  return(false);
  }
  else {
    MP3player.stopTrack();
    return(true);
  }
}


void loop (){
  volatile int tempPin = analogRead(potPin);
  volatile int pinValue = analogRead(potPin);
  pinValue = constrain (pinValue, 0, 1000);
  volatile int track = map (pinValue, 0, 1000, 1, 5);
  Serial.println(track);
  Serial.println(tempPin);
  delay(500);
  if (checkMovement (track) == false){
  }
  else {
   
  MP3player.playTrack(track);
}
 


 
}
Logged

Boston
Offline Offline
God Member
*****
Karma: 3
Posts: 575
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a similar issue.  I can't get Bill's library to work after the most recent update.
I gave up and base my code on the Sparkfun example. I've got mine switching tracks from a pot, but only after the current track ends.  Can't seem to stop the current track and start a new one on the fly.

The only time I use a volatile in is when I am using an interrupt.

Good luck.
Logged

Rio de Janeiro, BR
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I couldn't get Bill's library to work either.
But then i updated the SdFat library to the sdfatlib20120719, and it all worked!
Logged

Pages: [1]   Go Up
Jump to: