im using arduino ethernet shield(W5100) with arduinoUno and successful with the web server but when im trying to use SD card on it nothing is working..can't find the error.
after i enter the sd card that previously worked web server also not working..when i coppied a web page to sd card and uploaded with sd card web page sketch in serial moniter it says sd card and web page found..but when im trying to browse from web browser it won't show the web page.
please help me..im doing my finel year project with this and now im stuck.. ![]()
thankyou.
im using arduino ethernet shield(W5100) with arduinoUno and successful with the web server but when im trying to use SD card on it nothing is working..can't find the error.
You probably need something like below in your code setup area.
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
this is my code..
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// the router's gateway address:
byte gateway[] = { 10, 93, 7, 254 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };
IPAddress ip(10, 93, 7, 30); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
File webFile;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.begin(9600); // for debugging
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
serial monitor shows only this
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
im using my university network.i thought that is it the problem?i made the proxy settings...web server working..only when using SD card web page it is not working..
is it nedded to something called port forwarded.otherwise cant i access the filed in my SD????
please help me...
serial monitor shows only this
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
That should be the only stuff you see in the serial monitor as nothing else is printed to the serial monitor if the code successfully opens the SD card.
then it must be a problem with the network no????? how can i solve this...
harith:
im using arduino ethernet shield(W5100) with arduinoUno and successful with the web server but when im trying to use SD card on it nothing is working..can't find the error.
after i enter the sd card that previously worked web server also not working..
Out of RAM memory?
Complete code you are using?
Arduino UNO has only 2KB = 2048 Bytes of RAM and the SD library uses more than 1024 bytes for buffering two SD sectors a 512 bytes and holding some additional file system structures in RAM.
Perhaps you better use an Arduino MEGA when using Webserver and SD card at the same time?
im using arduino ethernet shield(W5100) with arduinoUno and successful with the web server but when im trying to use SD card on it nothing is working..can't find the error.
That indicates you probably do not have a network problem. Below is some web server SD test code that might be of use.
//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 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(){
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
Ethernet.begin(mac, ip, gateway, gateway, subnet);
//delay(2000);
server.begin();
Serial.println("Ready");
}
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("Content-Type: image/jpeg");
//client.println("Content-Type: image/gif");
//client.println("Content-Type: application/x-javascript");
//client.println("Content-Type: text");
client.println();
File myFile = SD.open("boom.htm");
//File myFile = SD.open("HYPNO.JPG");
//File myFile = SD.open("BLUEH_SL.GIF");
//File myFile = SD.open("SERVOSLD.HTM");
if (myFile) {
//Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
client.write(myFile.read());
}
// close the file:
myFile.close();
}
delay(1);
//stopping client
client.stop();
readString="";
}
}
}
}
}
jurs: and zoomkat: thank you for ur kind reply..
i tried mega also but it wont work....
i tried connecting my laptop and ethernet shield with a switch and it works web server code..but with SD card htm file, it is not working...
arduino finds the htm file but not showing it.. im stuck with this...
please help..
This has been known to cause network problems. You omitted the dns server parameter.
// change this
Ethernet.begin(mac, ip, gateway, subnet); // initialize Ethernet device
// to this
Ethernet.begin(mac, ip, gateway, gateway, subnet); // initialize Ethernet device
edit: Also, try disabling the SD card before starting the w5100.
void setup()
{
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
zoomkat:
That indicates you probably do not have a network problem. Below is some web server SD test code that might be of use.
Here is a simplified code that will initialize the SD card on an Ethernet shield and also will act as a webserver.
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define SD_CARD_SS 4 // Slave Select of SD is pin-4 on the Ethernet shield
File SDFileData;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 2, 177 );
EthernetServer server(80);
void setup()
{
pinMode(SS, OUTPUT); // set hardware Slave Select to OUTPUT
Serial.begin(9600);
if (!SD.begin(SD_CARD_SS))
{
Serial.println("ERROR: SD card failed to initialise");
}else
{
Serial.println("SD Card OK");
}
// Ethernet.begin(mac, ip); // assign fixed IP address
Ethernet.begin(mac); // or get ip address by using DHCP
Serial.print("Local IP: ");
Serial.println(Ethernet.localIP());
server.begin();
}
void loop()
{
EthernetClient client = server.available();
if (client) {
while (client.available() > 0) {
char thisChar = client.read();
Serial.write(thisChar);
}
client.println("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nIt works!");
delay(1);
client.stop();
}
}
If this works, then watch the correct steps in the setup() function:
- set hardware Slave Select to OUTPUT
- initialize SD card
- initialize Ethernet
OK?
If this works, then watch the correct steps in the setup() function:
- set hardware Slave Select to OUTPUT
- initialize SD card
- initialize Ethernet
Unless the Arduino is a Mega, then
- set hardware Slave Select to OUTPUT
- set D10 as OUTPUT and HIGH
- initialize SD card
- initialize Ethernet
thank you SurferTim: i made that changes but it continuously not working...
it shows a time out error msg after some time...why is it..
It works if the SD card is removed and fails with the card inserted? Have you tried another SD card?
Where do you see the timeout message? On the serial monitor or the web browser?
edit: You might want to try this test sketch with the SD card inserted. Does it show the IP 192.168.1.101 or something like 0.0.0.0?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,101);
void setup() {
Serial.begin(9600);
// disable SD SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// Start ethernet
Serial.println(F("Starting ethernet..."));
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
delay(2000);
Serial.println(F("Ready"));
}
void loop() {
}
hai jurs,
yeah it works.
it shows " It works!" in the browser
so what should i do next..
harith
SurferTim, thank you
no i havn't try another SD card ill try one
i see the time out message on web browser not in the serial monitor
i used ur test code and it shows
"
Starting ethernet...
10.93.7.30
Ready
"
only this in serial monitor and blank in browser...
i tried this all with my university network ill try these with a switch and let u know..please help me.
thnkyou again..
harith
If you want to access files on the SD card, then you need a web server sketch based on the SD card.
My server code on the playground is designed for an Arduino with a little more memory that an Uno.
http://playground.arduino.cc/Code/WebServerST
If you are using the server in a protected environment, like on a localnet isolated from the internet, you can remove some of the error checking and fault tolerance.
thank you very much SurferTim, ![]()
it worked i chnged my SD card and used your new code...it worked..great..thank you...again..
im implementing it to my final project.
thankyou all helped me.. ![]()
harith
now i need it to modify to
*- switch on and off 5 switches
*-see the states of the switches
*-and one slider(variable with 5 steps)
how can i change this code to my requirements..i cant find the wrong because this code having some complex parts..
help me with this...
Look for the code section that displays the mytest.php page. It is near the end of the code, just above the sendFileNotFound function.