Netduino: MP3 Player Shield

A couple of friends of mine gave me one of SparkFun's MP3 Player Shields for my birthday (this guy). I just got my order of Arduino Headers (strange how SparkFun don't send out shields with these by default) and finished soldering them on.

I've been playing around with it for a bit, and have just figured out how to read the mp3 file i placed on the SD card. The first thing I needed to do was to upgrade the firmware on my Netduino, because the firmware that comes with it does not support SD cards. The version 4.1.1 beta 1 (this guy) does the trick.

Once that's done, the next thing to do is to add references to the System.IO and the SecretLabs.NETMF.IO dll's (in your project for those people following along at home), and to include the using statements:

using System.IO;
using SecretLabs.NETMF.IO;

I placed an mp3 file (audio.mp3) in the root of my micro SD card, I don't see the need for any sort of fancy hierarchy (that may come later). Speaking of root, now's a good time to name the root of your SD card (i called mine MP3SD). Before you can read, you will need to mount the SD card. If you've been paying attention, you'll have noticed that the SD card chats to the Netduino over SPI and is sitting on pin 9, waiting for something to happen. So lets mount the thing:

// mount MP3 sd card
String sdroot = "MP3SD";
StorageDevice.MountSD(sdroot, SPI_Devices.SPI1, Pins.GPIO_PIN_D9);

Next up, lets try to read the directory structure, see whats happening with the files on the card:

// load mp3 file
String[] files = Directory.GetFiles(@"\" + sdroot);
Debug.Print("Files in root: " + files.Length);

String mp3File = "";
// for each file in the root
for (int i = 0; i < files.Length; i++)
    // if it is a valid mp3 file
    if (files[i].IndexOf(".mp3") != 0)
        mp3File = files[i];

// print out the filename
Debug.Print("MP3 File: " + mp3File);

At this point, if you look at the output log (ctrl + alt + o), you will see something similar to:

Files in root: 1

Pretty cool, eh? When i figure out whats next, i'll write an update.