Hello guys,,
I'm a little frustrated trying to connect an Arduino mega with an Ethernet Shield W5100,,
First, i'm using mac osx, IDE 1.5.6-r2, and the shield has "Mega compatible",, i'm using the sketch "WebServer",
The Ethernet Shield works fine with my arduino uno, i can use the Ethernet and i can read a micro-sd card.
so far as i know, the ethernet shield use ICSP to connect to arduino board, i was reading and i have to put pin 53 in OUTPUT,,
For SD, the SS use pin 4, and for ETH the SS use pin 10,,
If i'm i correct, into void setup, i should put:
pinMode(53, OUTPUT);
pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(10, LOW);
Correct?
any way.. i tried so many times, but something is wrong,
Here is the complete code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <EthernetServer.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte gateway[] = { 192, 168, 0, 1 };
IPAddress ip(192, 168, 0, 17);
EthernetServer server(8081);
void setup() {
pinMode(53, OUTPUT);
pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(10, LOW);
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(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) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
client.println("</html>");
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;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
Does anyone help me?
Thanks a lot guys!!