Arduino Ethernet Shield R3

The Ethernet Shield documentation states "There is an onboard micro-SD card slot, which can be used to store files for serving over the network". :~ I have tried many different ways but it seems this is impossible. Can I get some help with a code example on how to send a file from the SD car via Ethernet to a web server? Although I have been in IT for years I am very new to Arduino and C++.

DR

The information you have might be over simplifying the process.

You probably need to combine the ethernet server example and long with SD-card file examples.

Docs said “Note that because the W5100 and SD card share the SPI bus, only one can be active at a time. If you are using both peripherals in your program, this should be taken care of by the corresponding libraries. If you’re not using one of the peripherals in your program, however, you’ll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a high output.”

As soon as EthernetClient client = server.available(); hits it does not work

#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <DHT.h> // RHT03 Temperature Sensor
#define DHTPIN 2 // RHT03 data pin
#define DHTTYPE DHT22 // RHT03 acts like the DHT22
DHT dht(DHTPIN, DHTTYPE);

const int chipSelect = 4;
byte mac = {0x90, 0xA2, 0xDA, 0x00, 0xD9, 0x24 }; // MAC address
IPAddress ip(172,16,0, 65); // IP address
EthernetServer server(80);

void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print(“Initializing SD Card…”);
//pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
return;
}
Serial.println(“card initialized.”);

Serial.print(“Initializing Temperature Sensor…”);
dht.begin();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println(“Failed to read from DHT”);
} else {
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.println(” *F”);
}

Serial.print(“Initializing Ethernet Interface…”);
Ethernet.begin(mac, ip);
server.begin();
Serial.print(“IP:”);
Serial.println(Ethernet.localIP());

}

void loop() {
EthernetClient client = server.available();

String strClient; //Buffer to hold the string of text from the browser
String strClientCMDLine; //Holds the first line of text from the browser
String strClientCMD; //Holds the command sent from the browser
String strClientURI; //Holds the URI the browser sent
String strClientxx; //Just a temp buffer

boolean currentLineIsBlank = true;

while (client.connected()) {
if (client.available()) {
char c = client.read();
strClient.concat(c);
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == ‘\n’ && currentLineIsBlank) {
// Gets the first line of text from the browser (We don’t need the rest at this time
strClientCMDLine = strClient.substring(0,strClient.indexOf(’\r’));
strClientCMD = strClientCMDLine.substring(0,strClientCMDLine.indexOf(0x20)-1);

// send a standard http response to the browser and let it know you got the request.
client.println(“HTTP/1.1 200 OK”);
Serial.println(strClientCMD);
if (strClientCMD = “GET”) {
strClientxx = strClientCMDLine.substring(strClientCMDLine.indexOf(0x20)+1);
strClientURI = strClientCMDLine.substring(strClientxx.charAt(0x20),strClientxx.charAt(0x20)-1);
Serial.println(strClientURI);
if (strClientURI = “/”) {

client.println(“Content-Type: text/html”);
client.println(“Connnection: close”);
client.println();
client.println("<html xmlns=“http://www.w3.org/1999/xhtml">");
client.println(”");
client.println("");
client.println(“Some Title”);
client.println("");
client.println("");

client.println("<div id=“container” style=“width:1000px”>");

client.println(“xxx”);

client.println("");
client.println("");
client.println("");
};
};
if (strClientCMD = “POST”) {

};
if (strClientCMD = “HEAD”) {

};

break;
}
if (c == ‘\n’) {
// you’re starting a new line
currentLineIsBlank = true;
}
else if (c != ‘\r’) {
// you’ve gotten a character on the current line
currentLineIsBlank = false;
}
}
}
}

The only way I found to effectively use both SD and Ethernet is to set the appropriate slave/chip select line low as the documentation says to do just before you write code that deals with that specific device. so my rough sketch looked something like this:

void setup () {
setEthernet ();
setup ethernet here
setSD();
setup sd card here
 }
void loop(){
setEthernet ();
 check for clients....
setSD();
read information from a file....
setEthernet ();
send information over internet.... 
}
void setSD(){
  digitalWrite(ethernet_cs, HIGH);
  digitalWrite(sd_cs, LOW);
  return;
}

void setEthernet(){
  digitalWrite(sd_cs, HIGH);
  digitalWrite(ethernet_cs, LOW);
  return;
}

I know it seems clunky , but it worked for me. Some more experienced programmers may have a better way to do it.

Docs said "Note that because the W5100 and SD card share the SPI bus, only one can be active at a time. If you are using both peripherals in your program, this should be taken care of by the corresponding libraries. If you're not using one of the peripherals in your program, however, you'll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a high output."

So, where in that information, did you get the idea to do this?

//pinMode(10, OUTPUT);

Here is a link to a setup routine for both SD and w5100 that works for me. http://arduino.cc/forum/index.php/topic,111352.msg837189.html#msg837189

After this setup, you can access both devices without managing the SS lines. That is done by the low level library read/write routines for each device.