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.

有帮助吗?

解决方案

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)

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top