It relies on the sdfatlib from Bill Greiman: http://code.google.com/p/sdfatlib/ You will need to download and install his library. To compile, you MUST change Sd2PinMap.h of the SDfatlib! The default SS_PIN = 10;. You must change this line under the ATmega328/Arduino area of code to uint8_t const SS_PIN = 9;. This will cause the sdfatlib to use pin 9 as the 'chip select' for the microSD card on pin 9 of the Arduino so that the layout of the shield works.

//Setup SD card interface pinMode(9, OUTPUT); //Pin 10 must be set as an output for the SD communication to work. if (!card.init(SPI_FULL_SPEED)) Serial.println("Error: Card init"); //Initialize the SD card and configure the I/O pins. if (!volume.init(&card)) Serial.println("Error: Volume ini"); //Initialize a volume on the SD card. if (!root.openRoot(&volume)) Serial.println("Error: Opening root"); //Open the root directory in the volume.

uint8_t mp3DataBuffer[32]; //Buffer of 32 bytes. VS1053 can take 32 bytes at a go. //track.read(mp3DataBuffer, sizeof(mp3DataBuffer)); //Read the first 32 bytes of the song int need_data = TRUE; long replenish_time = millis();

Serial.println("Start MP3 decoding");

while(1) { while(!digitalRead(MP3_DREQ)) {

if(need_data == TRUE) { if(!track.read(mp3DataBuffer, sizeof(mp3DataBuffer))) { //Try reading 32 new bytes of the song //Oh no! There is no data left to read! //Time to exit break; } need_data = FALSE; }

replenish_time = millis(); } if(need_data == TRUE){ //This is here in case we haven't had any free time to load new data if(!track.read(mp3DataBuffer, sizeof(mp3DataBuffer))) { //Go out to SD card and try reading 32 new bytes of the song //Oh no! There is no data left to read! //Time to exit break; } need_data = FALSE; }

Musical Instrument Shield is an easy way to add great sounding MIDI sound to your next Arduino project. This board is built around the VS1053 MP3 and MIDI codec IC, wired in MIDI mode. Simply connect a speaker/stereo/pair of headphones to the 1/8" stereo jack on the shied and pass the proper serial commands to the IC and you'll be playing music in no time!