Sunday, October 23, 2011

Netduino: Using Ethernet Shield to Read/Write to SD Card

After successfully running a program that writes a file to SD card and then reads the content I've decided to summarize all the steps required in order to use Netduino with Ethernet Shield and SD card.

First, you have to upgrade the firmware (I used v4.1.1.0 Beta 1 which can be found here. The detailed instructions about firmware upgrade are available at the same address.

Next, you have to solder ICSP pin on your Netduino board and connect D4 with D10 with jumper wire as it is shown on pictures below.





After adding the ICSP header and jumper wire, the hardware is ready and you can write a program to use the SD card reader. Below is the example I used for test and it worked fine.



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using SecretLabs.NETMF.IO;
using System.IO;

namespace NetduinoSD
{
public class Program
{
public static void Main()
{
StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Create))
{
StreamWriter streamWriter = new StreamWriter(filestream);
streamWriter.WriteLine("This is a test of the SD card support on the netduino...This is only a test...");
streamWriter.Close();
}

using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Open))
{
StreamReader reader = new StreamReader(filestream);
Debug.Print(reader.ReadToEnd());
reader.Close();
}

StorageDevice.Unmount("SD");


}

}
}



The whole solution for Visual Studio 2010 can be found here

2 comments:

  1. Hi Niko,

    I'm trying to use your test project with new netmf 4.2 release (12-14 Aug 2012). The line

    using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Create)

    causes an Exception:
    Message = "Exception was thrown: System.NotSupportedException"

    Can you help me?

    Warm regards,
    Slava V.

    ReplyDelete
    Replies
    1. The reason, probably, was unsupported SD size. Now I am trying to use SD 2G and it is working good.
      Thanks!
      Slava V.

      Delete