Help!!! With Ethernet shield read HTML file from SD


I have an Ethernet shield HR911105A with SD card slot. Is it some ways there I can read HTML files from the SD card with the ethernet shield???
There I use it as a Web Server for the HTML file on the SD card.


PS: Sorry for my bad English :stuck_out_tongue:

Yes, it can be done. There is no built-in example for it. A Google search turned up this tutorial: Arduino Tutorials - Ethernet+SD

Below is some copy/paste test code for loading a .htm file from the SD card and displaying it in a browser. Note the code that does the SD card and ethernet shield setup. Put your SD card in a computer and load a simple .htm file on it (boom.htm in this example), then try the code.

//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 


void setup(){


  // disable w5100 while setting up SD
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);



void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
        //if HTTP request has ended
        if (c == '\n') {

          Serial.println(readString); //print to serial monitor for debuging 

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");

          File myFile ="boom.htm");
          if (myFile) {
            // read from the file until there's nothing else in it:
            while (myFile.available()) {
            // close the file:

            //stopping client

I also but some images on the SD to have one the HTML file but that did`n work, why???


That code is not parsing the GET request for the file name. It returns the same HTML doc no matter what the web browser requests. So when your web browser requests favicon.ico or any other image file, like a jpeg or gif, the code returns that web page instead.

edit: This server code in the playground parses out the GET request line and displays it on the serial monitor. It might make it easier to see what you are working with.
When sending an image you will need to send the correct "Content-Type" and "Content-Length" header parameters.

File type selection process.

          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
             client.println("Content-Type: text/html");
         else if (strstr(filename, ".css") != 0)
             client.println("Content-Type: text/css");
         else if (strstr(filename, ".png") != 0)
             client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
             client.println("Content-Type: image/jpeg");
         else if (strstr(filename, ".gif") != 0)
             client.println("Content-Type: image/gif");
         else if (strstr(filename, ".3gp") != 0)
             client.println("Content-Type: video/mpeg");
         else if (strstr(filename, ".pdf") != 0)
             client.println("Content-Type: application/pdf");
         else if (strstr(filename, ".js") != 0)
             client.println("Content-Type: application/x-javascript");
         else if (strstr(filename, ".xml") != 0)
             client.println("Content-Type: application/xml");
             client.println("Content-Type: text");

Where should i put that code

Where should i put that code

If you use the code I posted the selection process would look like below (not tested). It goes where the origional file type line was located.

            client.println("HTTP/1.1 200 OK"); //send new page

             if(readString.indexOf(".htm") >=0)
             client.println("Content-Type: text/html");
         else if(readString.indexOf(".gif") >=0)
             client.println("Content-Type: image/gif");             
         else if(readString.indexOf(".js") >=0)
             client.println("Content-Type: application/x-javascript");            
            //client.println("Content-Type: text/html");

Doing some testing, .jpg and .gif files seem to be unaffected in IE when the below file type is used.

client.println("Content-Type: text/html");