Ethernet + SD support (software mod)

http://www.ladyada.net/learn/arduino/ethfiles.html

The latest Arduino Ethernet shield comes with a handy MicroSD card slot so that you can store and retrieve data through the shield. Very handy! Lets show how to talk to the card.

Be sure to have the very latest version of SdFatLib , as you'll need some of the newer capabilities!

First thing to note is that the SS (Slave Select) pin for the card is digital 4 (although as of the writing of this mini-tutorial, the schematic hasn't been updated, you'll have to trust me!)

Open up the SdFatInfo example sketch and change the line in loop() from

uint8_t r = card.init(SPI_HALF_SPEED);

To:

pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
uint8_t r = card.init(SPI_HALF_SPEED, 4); // Use digital 4 as the SD SS line

Be sure to add those two extra lines right before-hand! They Enable the SPI interface. If you're on a Mega, use pin 53 instead of 10

Now upload and test the card, you should see something like this:

I have a couple of questions about the way this works..

  1. Can't the default library that comes with Arduino 1.0 be modified in the same way?.

  pinMode(10, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH);                    // but turn off the W5100 chip!

A. Should pin 10, not be automatically set as an output anyway? what was it "prior"
B. 10,LOW turns off the wiznet chip at any point? in the code, would this make 10,11,12 (eg, the pins it uses, now safe to use?)

I also read this at Ladyada.
First of all, use the newest Arduino 1.0.1, and use the examples provided with it.

And I initialize the SD card before I initialize the Ethernet W5100.
So this is my code:

// With the ethernet shield, the chip select for the
// SD card is not SS (in use for ethernet), but pin 4.
const int chipSelectSD = 4;

...

  // make sure that the default chip select pin is set to
  // output for the SD, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // According to this:
  //   http://www.ladyada.net/learn/arduino/ethfiles.html
  // The SS (pin 10) has to be high to disable the W5100
  digitalWrite(10, HIGH);

  // Initializing the SD before the ethernet W5100.
  if (!SD.begin(chipSelectSD)) 
  {
    // The SD card can't be found.
    Serial.println(F("SD.begin failed"));
  }

  Ethernet.begin ...
  server.begin ....

So I don't use the "card.init", but I use SD.open().