1

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)

Enter image description here

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
  • Could you clarify the Ethernet Shield model that you are using. I believe there was a version available for a long time that had the SD Card slot but didn't actually support it. So what company and approximately when did you buy it? – James Oct 19 '11 at 16:43
  • That is the latest and doesn't have the issue I was referring too. I'm sorry I don't have any experience with it and can't offer much help. If you would like to share one of the code examples you are working from maybe I and others here can provide "a second set of eyes" for you. – James Oct 19 '11 at 19:38

2 Answers2

2

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)

Chris Walker
  • 196
  • 1
  • 3
  • I added the ICSP header, upgraded firmware to v4.1.1.0 Beta1 but the applcation still throws an exception: An unhandled exception of type 'System.IO.IOException' occurred in SecretLabs.NETMF.IO.dll – Niko Gamulin Oct 23 '11 at 09:06
  • Now I added a jumper wire that connects D4 and D10 and it works. – Niko Gamulin Oct 23 '11 at 09:09
0

I found a reference on this forum page http://forums.netduino.com

"you'll currently need to put a jumper wire between D10 and D4 to get the SD card to work--although that will not be necessary with the production v4.1.1 firwmare (which will let you specify the SD card's chip select line)."

Which makes me think that you need to use D4 instead of D10 for the SD Card. I found some other references on the same page that mentioned D10 is the SS pin for the Ethernet. The Firmware available on their download page is currently only 4.1.0 so you will probably need the jumper. I can't test this but the forum link should be a good starting point.

James
  • 330
  • 1
  • 12