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

#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.      }