I have tried several example programs to write data to the SD card mounted on the Ethernet shield, but none worked. The SD card size is 4 GB and formatted as FAT32.
The Ethernet shield is the following:
(Bought on Amazon - Arduino Ethernet Shield)
And this is example code that doesn't work when creating a Netduino application (not Netduino Plus application) (thefirst line throws an exception):
public static void Main()
{
StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);
string[] directories = System.IO.Directory.GetDirectories(@"\");
Debug.Print("directory count: " + directories.Length.ToString());
for (int i = 0; i < directories.Length; i++)
{
Debug.Print("directory: " + directories[i]);
}
string[] files = System.IO.Directory.GetFiles(@"\SD1");
Debug.Print("file count: " + files.Length.ToString());
for (int i = 0; i < files.Length; i++)
{
Debug.Print("filename: " + files[i]);
FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
StreamReader sr = new StreamReader(fs);
Debug.Print("contents: " + sr.ReadToEnd());
}
}
Is there a example working program?
Solution:
Thanks to Chris and James, I managed to write to the SD card and read from it. After putting everything together, I wrote an article, in case anyone else faces the same issues.
The latest revision of the Arduino Ethernet Shield uses the "ICSP" header (3x2, 6-pin header on right side of board) to communicate. The input/output data going to your SD card is going over those pins.
We've included these same headers on the Netduino for compatibility; to use this shield, you'll want to solder the appropriate header onto your Netduino. Then you should be good to go!
BTW, Netduino Plus has integrated MicroSD and fast Ethernet networking...which may be an easy solution as well. http://www.netduino.com/netduinoplus/
Chris (Secret Labs LLC)