Home Forums Sparkfun MP3 Shield Library Support Forum SFEMP3Shield + Ethernet Shield + Arduino Mega

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2632
    Anonymous
    Inactive

    Great library, btw!

    I have a home automation build that is using an Arduino Mega, a SainSmart Ethernet shield, and a MP3 breakout board. I remapped the SPI pins for the Mega per other posts here/library documentation. I can get the MP3 breakout board to run all day long on the Mega by itself this way.

    The rest of my build runs fine by itself. The problems begin when folding the MP3 breakout board together with the Ethernet shield. They both seem to be conflicting across pins 2, 6, 7, 8 and 9. I tried duplicating the library then altering the config file to map pins 2, 6, 7, 8 and 9 to pins 22-26 on Mega. It partially works this way but I get partial track playback, garbled audio, and loads of other issues.

    Is there a way to do this properly on the Mega? My Sainsmart Ethernet Shield also has a micro SD card on it, so maybe the pin conflicts are with its onboard (empty) SD card slot?

    #2633
    Anonymous
    Inactive

    I think I may have figured it out. I am going to leave this build running overnight to see if it stays stable. Here is what is working currently for me.

    Hardware

    Instead of using the Sparkfun shield for MP3 playback, I am using another MP3 breakout board ( http://amzn.com/B009Z620PI ) so I can jumper the connections on the Mega easily. So following the instructions in the SFEMP3Shield library Read Me, I jumped pins 13, 12, and 11 to pins 50, 51, and 52 on the Mega. I loaded a 4GB SD with MP3s into the MP3 breakout board. I am using the SainSmart Ethernet Shield with this breakout board ( http://amzn.com/B006J4FZTW ).

    Software

    I am using the following code in the initialization for the Ethernet shield, MP3 shield, and its on board SD card reader. The big change was in the setup loop. I changed to sd.begin(SD_SEL, SPI_HALF_SPEED); to sd.begin(SD_SEL, SPI_FULL_SPEED); and both shields started to magically work together. Note: you may not need the webserver part below – I am using that to pass data back to my web app via GET.

    // INITIALIZE

    #define WEBDUINO_FAIL_MESSAGE “<h1>Request Failed</h1>”  //For the webserver

    #include <SPI.h>

    #include “avr/pgmspace.h”

    #include “Ethernet.h”

    #include “WebServer.h”  //For the webserver

    #define VERSION_STRING “0.1”

    #include “SdFat.h”

    #include “SdFatUtil.h”

    #include “SFEMP3Shield.h”

    SdFat sd;

    SFEMP3Shield MP3player;

     

    Then in the Setup loop I use.

    /*  Start Ethernet Shield and webserver  */

    Ethernet.begin(mac, ip);                                               // initialize the Ethernet adapter

    webserver.setDefaultCommand(&helloCmd);             // setup our default command that will be run when the user accesses  webserver.setFailureCommand(&my_failCmd);         // setup our default command that will be run when the user accesses  webserver.addCommand(“index.html”, &helloCmd);  // run the same command if you try to load /index.html

    webserver.begin();                                                       // start the webserver

    /*  Start MP3 Shield  */

    sd.begin(SD_SEL, SPI_FULL_SPEED);

    MP3player.begin();

     

    Then in my functions/loop I have to tell the Arduino to wait until the MP3 is finished playing before moving on to the next line of code. Otherwise it will hang up.

    MP3player.playTrack(1);

    while (MP3player.isPlaying());

     

    Here is that same code in context of a full command from my controlling web app…

    if (*commands == ‘D’) {  //——> Zone 01 lighting OFF command from web app

    MP3player.playTrack(1);

    digitalWrite(relayPin01, LOW); //Relay for zone 01’s lighting

    while (MP3player.isPlaying());

    *commands = ‘X’;  //Resets the commands var. Used X for exit.

    }      if (*commands == ‘C’) {  //——> Zone 01 lighting ON command from web app

    MP3player.playTrack(2);

    digitalWrite(relayPin01, HIGH);  //Relay for zone 01’s lighting

    while (MP3player.isPlaying());

    *commands = ‘X’;  //Resets the commands var. Used X for exit.      }

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