Go Down

Topic: how to load image from SD Card into arduino HTML that created (Read 747 times) previous topic - next topic

wawi

Hello, i'm new in arduino. I got problem to load the image from sd card. i've been tried many way but still not compatible with my code.
here is my code

Code: [Select]


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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 6 }; // ip in lan
EthernetServer server(80); //server port

String readString;
String s;
String ss;
//////////////////////

void setup(){

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT); //pin selected to control
  pinMode(7, OUTPUT); //pin selected to control
  pinMode(8, OUTPUT); //pin selected to control
  pinMode(9, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  //start Ethernet
  Ethernet.begin(mac, ip);
  server.begin();

  //enable serial data print
  Serial.begin(9600);
  Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
}

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

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(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");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>LED NOTIFY STATUS</TITLE>");
          client.println("</HEAD>");
          client.println("<body style='background-color:rgb(255,255,204);'>");
          client.println("<img src=kpm.jpg>");             
         
          client.println("&nbsp;<font color=black><H1 align=center>LECTURER STATUS</font> </H1><br><br>");
          client.println("*******PLEASE DOUBLE CLICK ON THE BUTTON ********");
          // For simple testing, pin 5, 6, 7, and 8 are used in buttons
         client.println("<font color=black><H2 align=center>Day</font> </H2>");
     

          // mousedown buttons
          client.println("<input type=button value=ISNIN onmousedown=location.href='/?ISNIN2;'>");
          client.println("<input type=button value=SELASA onmousedown=location.href='/?SELASA3;'>");
          client.println("<input type=button value=RABU onmousedown=location.href='/?RABU5;'>");
          client.println("<input type=button value=KHAMIS onmousedown=location.href='/?KHAMIS6;'>");   
          client.println("<input type=button value=JUMAAT onmousedown=location.href='/?JUMAAT7;'>");
          client.println("&nbsp;<input type=button value='ALL OFF' onmousedown=location.href='/?off4;'><br><br>");
          client.println(s);
         
          client.println("<font color=black><H2 align=center>STATUS</font> </H2>");
          client.println("<input type=button value=ADA onmousedown=location.href='/?ada8;'>");
          client.println("<input type=button value=KELAS onmousedown=location.href='/?kelas9;'>");
          client.println("<input type=button value=BERCUTI onmousedown=location.href='/?bcuti@;'>");
          client.println("<input type=button value=MESYUARAT onmousedown=location.href='/?mesyuarat%;'>");   
          client.println("<input type=button value=BERTUGAS DILUAR onmousedown=location.href='/?btgsDLuar$;'>");
          client.println("&nbsp;<input type=button value='ALL OFF' onmousedown=location.href='/?off10;'><br><br>");
          client.println(ss);
         
          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf('2') >0)//checks for 2
          {
            s=("ISNIN");
            digitalWrite(2, HIGH);    // set pin 5 high
            Serial.println("Led 2 On");
           
          }
          if(readString.indexOf('3') >0)//checks for 3
          {
            s=("SELASA");
            digitalWrite(3, HIGH);    // set pin 5 low
            Serial.println("Led 3 On");
          }
          if(readString.indexOf('5') >0)//checks for 4
          {
            s=("RABU");
            digitalWrite(5, HIGH);    // set pin 6 high
            Serial.println("Led 5 On");
          }
          if(readString.indexOf('6') >0)//checks for 5
          {
             s=("KHAMIS");
            digitalWrite(6, HIGH);    // set pin 6 low
            Serial.println("Led 6 On");
          }
          if(readString.indexOf('7') >0)//checks for 6
          {
            s=("JUMAAT");
            digitalWrite(7, HIGH);    // set pin 7 high
            Serial.println("Led 7 On");
          }
           if(readString.indexOf('4') >0)//checks for 7
          {
            s=("OFF");
            digitalWrite(2, LOW);    // set pin 7 low
            digitalWrite(3, LOW);
            digitalWrite(5, LOW);
            digitalWrite(6, LOW);
            digitalWrite(7, LOW);
            Serial.println("All Led OFF");
          }         
         
          if(readString.indexOf('8') >0)//checks for 2
          {
            ss=("ADA");
            digitalWrite(8, HIGH);    // set pin 5 high
            Serial.println("Led 8 On");
          }
          if(readString.indexOf('9') >0)//checks for 3
          {
            ss=("KELAS");
            digitalWrite(9, HIGH);    // set pin 5 low
            Serial.println("Led 9 On");
          }
          if(readString.indexOf('@') >0)//checks for 4
          {
            ss=("BERCUTI");
            digitalWrite(11, HIGH);    // set pin 6 high
            Serial.println("Led 11 On");
          }
          if(readString.indexOf('%') >0)//checks for 5
          {
            ss=("MESYUARAT");
            digitalWrite(12, HIGH);    // set pin 6 low
            Serial.println("Led 12 On");
          }
           if(readString.indexOf('$') >0)//checks for 6
          {
            ss=("BERTUGAS DI LUAR");
            digitalWrite(13, HIGH);    // set pin 7 high
            Serial.println("Led 13 On");
          }
           if(readString.indexOf('10') >0)//checks for 7
          {
            ss=("STATUS OFF");
            digitalWrite(8, LOW);    // set pin 7 low
            digitalWrite(9, LOW);
            digitalWrite(11, LOW);
            digitalWrite(12, LOW);
            digitalWrite(13, LOW);
            Serial.println("All Led OFF");
          }         
         
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}


please help me in this problem.

SurferTim

You must use server code that is capable of parsing the request for the image files. Mine has that capability.
http://playground.arduino.cc/Code/WebServerST

wawi

Does it going to change my code?
because i don't want to change it just add it for me to load the image in sd card..

sorry for my english

SurferTim

You don't have to change your code, but it won't upload any files from the SD card if you don't.

The code in the link I posted above is the minimum for me. Take what you need from that if you wish, but it won't have any fault tolerance if you remove anything.

wawi

thank you SurferTim. Now i can load the image from SD Card :)

really big thank you

Go Up