Ethernet-Shield with SD-Slot

Hy... I try to make a Webserver with my Ethernet-Shield.

This one -->

http://www.amazon.de/Aukru-Ethernet-Micro-SD-Kartensteck-Arduino/dp/B00PL70PA2/ref=sr_1_1?ie=UTF8&qid=1453318572&sr=8-1&keywords=arduino+ethernet+shield

If i write my HTML Code in the development environment everything works fine.

And when i try to read from the SD-card without ethernet Code,

I´m only use the code for the sd card, that also works.

But I got a problem when I save my HTML Code on the SD-Card.

When I include the Sketch for the sd-card, the ethernet client is not available.

Could it be that is not possible to use the SD Card and the ethernet connecten in the same Sketch.

I watched a few Videos on Youtube and the all used the small ethernet shield.

This one -->

http://www.amazon.de/ENC28J60-Ethernet-Netzwerk-Modul-Arduino/dp/B00FR7DX0K/ref=sr_1_6?ie=UTF8&qid=1453318572&sr=8-6&keywords=arduino+ethernet+shield

I hope someone can help me

Thx

Sorry for my bad english

The first one uses the W5100 chip, and that is the same chip as on the official Ethernet Shield. The Arduino Ethernet libraries are written for that chip.

The second one uses the ENC28J60, which is not official supported by Arduino. There are two libraries for it, the UIPEthernet (compatible with the Arduino Ethernet library) and the EtherCard. I suggest to stay with the W5100.

When you buy a cheap clone with bad quality components, buy a 'R3' version. It is best when the Arduino Uno or the Arduino Mega 2560 and the Ethernet Shield are all 'R3' version. Why did you pay so much money. If you are willing to buy a cheap and unreliable clone, then at least don't spent too much money. They are below 6 dollars on Ebay: www.ebay.com/itm/151445047067

The SD card and the Ethernet will work together of course. Could you show your sketch ?

Hy

#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 };

IPAddress ip(10, 0, 0, 20); // 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); // 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: 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)
}

When I open the serial montior I see “SUCCESS - Found index.htm file.”

But If I open my browser and conntect to the arduino nothing happens ;(

I don't see the problem, but I noticed a few things you need to fix.

First of all, use code tags for your sketch. It is number 7 on this page : http://forum.arduino.cc/index.php/topic,148850.0.html

Please use indents and spaces and brackets always in the same way. Try the command in the menu : Tools / Auto Format

Add a check for webFile. Print to the serial monitor if opening that file was successful or not.

Split this : client.write ( webFile.read() ) ; Use a char or byte. That makes it possible to print it also to the serial monitor. It also prevents that a .read() is turned into an integer and a integer is printed.

The SPI bus could be confused. When the Ethernet starts, the digital pin 4 is not initialized. And it is the enable for the SD card. You could set pin 10 and pin 4 as output, and make them high and wait a few milliseconds. After that the Ethernet.begin().

Hy

Thank you for your tip, next time I´ll use the Code tag.

No it works :)

I changed the SD-Card, I suppose this was the problem.

THX

Well done, I didn't think of that. Could you still fix the things that I mentioned ? Have you read this : http://forum.arduino.cc/index.php?topic=228201.0 I use it for all my sd cards that are used with Arduino.

I changed the SD-Card, I suppose this was the problem.

I think it may be possible for an arduino to mess up the format on an SD card. I always put the SD card in the pc for loading stuff on it. Try the card in a pc and see if it works. If not, try to reformat the card.