Home Forums Sparkfun MP3 Shield Library Support Forum MP3 runs first file and then the code "stuck"

  • This topic has 1 reply, 2 voices, and was last updated 9 years ago by Bill.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3265
    Anonymous
    Inactive

    Hi,

    I will be grateful for your help!
    I’m running the simple code below, with sparkfun mp3 & Mega 2560 (with the corresponding jumpers <span style=”color: #000000; font-family: monospace; font-size: 14px; line-height: 22px; background-color: #ffffff;”>Mega’s 51 to the MP3’s D11 for MOSI, </span><span style=”color: #000000; font-family: monospace; font-size: 14px; line-height: 22px; background-color: #ffffff;”>Mega’s 50 to the MP3’s D12 for MISO,</span><span style=”color: #000000; font-family: monospace; font-size: 14px; line-height: 22px; background-color: #ffffff;”>Mega’s 52 to the MP3’s D13 for SCK</span><span style=”color: #000000; font-family: monospace; font-size: 14px; line-height: 22px; background-color: #ffffff;”> )</span> .

    The problem is that the first button pressing works and the file is being played, but from then on there is no more response.

    If I repress one of the two buttons (I tried to press many times many possibilities) it doesnt show the debug line and does not play anything.

    Why this is happening? what should I do to fix it?

    Thanks in advanced,

    Lola

     

    /*

    MP3 Shield Trigger

    by: Jim Lindblom

    SparkFun Electronics

    date: September 23, 2013*/

     

    #include <SPI.h>           // SPI library

    #include <SdFat.h>         // SDFat Library

    #include <SdFatUtil.h>     // SDFat Util Library

    #include <SFEMP3Shield.h>  // Mp3 Shield Library

     

    SdFat sd; // Create object to handle SD functions

     

    SFEMP3Shield MP3player; // Create Mp3 library object

    // These variables are used in the MP3 initialization to set up

    // some stereo options:

    const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)

    const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

     

    /* Pin setup */

    #define TRIGGER_COUNT 2

    int triggerPins[TRIGGER_COUNT] = {45,46};

    int stopPin = A5; // This pin triggers a track stop.

    int lastTrigger = 0; // This variable keeps track of which tune is playing

     

    void setup()

    {

    Serial.begin(9600);

    /* Set up all trigger pins as inputs, with pull-ups activated: */

    for (int i=0; i<TRIGGER_COUNT; i++)

    {

    pinMode(triggerPins[i], INPUT_PULLUP);

    }

    pinMode(stopPin, INPUT_PULLUP);

     

    initSD();  // Initialize the SD card

    initMP3Player(); // Initialize the MP3 Shield

    uint8_t result = MP3player.begin();

    }

     

    // All the loop does is continuously step through the trigger

    //  pins to see if one is pulled low. If it is, it’ll stop any

    //  currently playing track, and start playing a new one.

    void loop()

    {

    for (int i=0; i<TRIGGER_COUNT; i++)

    {

    if ((digitalRead(triggerPins[i]) == LOW) && ((i+1) != lastTrigger))

    {

    Serial.println (i); //debug

    lastTrigger = i+1; // Update lastTrigger variable to current trigger

    /* If another track is playing, stop it: */

     

    /* Use the playTrack function to play a numbered track: */

    MP3player.stopTrack();

    uint8_t result = MP3player.playTrack(lastTrigger);

    // An alternative here would be to use the

    //  playMP3(fileName) function, as long as you mapped

    //  the file names to trigger pins.

     

    if (result == 0)  // playTrack() returns 0 on success

    {

    // Success

    }

    else // Otherwise there’s an error, check the code

    {

    // Print error code somehow, someway

    }

    }

    }

     

    }

     

    // initSD() initializes the SD card and checks for an error.

    void initSD()

    {

    //Initialize the SdCard.

    if(!sd.begin(SD_SEL, SPI_HALF_SPEED))

    sd.initErrorHalt();

    if(!sd.chdir(“/”))

    sd.errorHalt(“sd.chdir”);

    }

     

    // initMP3Player() sets up all of the initialization for the

    // MP3 Player Shield. It runs the begin() function, checks

    // for errors, applies a patch if found, and sets the volume/

    // stero mode.

    void initMP3Player()

    {

    uint8_t result = MP3player.begin(); // init the mp3 player shield

    if(result != 0) // check result, see readme for error codes.

    {

    // Error checking can go here!

    }

    MP3player.setVolume(volume, volume);

    MP3player.setMonoMode(monoMode);

    }

     

     

    #3286
    Bill
    Member

    Do you see the debug statements in you serial terminal each time you push a button?

     

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.