sorry if the question seems to be stupid to you, but I currently can´t get the solution on my own and I am a beginner using Arduino as I come from BASCOM...thanks for understanding.
The current hardware I try to use is
Arduino Leonardo (also tried Arduino UNO - successful)
Arduino Ethernet shield (W5100)
The current software:
SAMPLE of Arduino ETHERNET -> Webserver
Now the "simple" problem:
1 When I use the Arduino Uno with the Arduino Ethernet shield, everything works fine.
2 When I use the Arduino Leonardo with the Arduino Ethernet shield, it cannot be reached, pinged or found in my LAN.
2.1 I recognized that there are some coding lines in the sample (Setup -> serial wait) which is only relevant for the Leonardo. This command is within the coding and active
2.2 I also read something about the different SPI connectors from the Arduino. Maybe this is the problem?
2,2.1 If yes - what do I have to change? Means: Which PINs do I have connect from the Leonardo to the Ethernet shield, and which PINs do I have to disconnect?
2.2.2 If not - what could be the the problem? I guess that it "should" work; otherwise the additional line in the coding wouldn´t make sense.
The Arduino Ethernet Shield should work on the Arduino Leonardo, but I'm getting the same symptom as you. The WebServer example works fine on an Arduino UNO (R2) but fails to be reachable by the web browser when run on a Leonardo (a clone, in my case).
I found a mention that the problem might be that the pins on the Ethernet shield are too long and the ICSP connector on the bottom of the Ethernet shield doesn't quite reach all the ICSP pins on the Leonardo. (http://forum.arduino.cc/index.php?topic=108592.0) I tried a spring clamp on the boards to force the ICSP connectors together but that didn't fix the problem.
I was able to get it to work by bringing my laptop to the ethernet router, starting the Serial Monitor and setting the baud rate to 9600. It appears that something goes wrong if the messages being logged by the WebServer sketch don't have anywhere to go.
With the Leonardo (clone) connected by USB to the laptop and Serial Monitor set to 9600 baud the laptop web browser (running over WiFi) would refresh the page every five seconds and a bunch of messages would be logged in Serial Monitor:
new client
GET / HTTP/1.1
Host: 10.0.1.177
Accept-Encoding: gzip, deflate
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5
Accept-Language: en-us
Referer: http://10.0.1.177/
Cache-Control: max-age=0
johnwasser:
I was able to get it to work by bringing my laptop to the ethernet router, starting the Serial Monitor and setting the baud rate to 9600. It appears that something goes wrong if the messages being logged by the WebServer sketch don't have anywhere to go.
This is interesting. Do other sketches lock up if serial is sent while not attached to anything through the USB?
samazw:
Do I have to adjust the Pins or anything in the coding?
No. I only had to adjust the IP address because my router is at 10.0.1.1 instead of 196.168.0.1. With that adjustment the same sketch runs on both UNO and Leonardo.
KenF:
Do other sketches lock up if serial is sent while not attached to anything through the USB?
Not that I can tell. I added a Serial.println("Blink"); to the BlinkWithoutDelay example and it worked fine with or without the Serial Monitor running. With Serial Monitor running the TX LED would blink each time the message was send and when Serial Monitor was shut down the TX LED didn't blink. Also works fine running off a USB Charger instead of a USB port.
samazw:
But when you say it works fine - did you do any changes ?
Sorry for asking again - with regards
Samazw
I was able to get the Leonardo to work by connecting it via USB to my laptop, running Serial Monitor, setting Serial Monitor to 9600 baud, connecting the laptop's Safari browser to the fixed IP address (10.0.1.177 in my case) and pressed the reset buttons or cycled power. The browser connected and displayed the analog inputs, refreshing every five seconds. The Serial Monitor displayed output each time the browser connected.
I should try removing the serial output from the sketch! BRB
It works. Commenting out all the Serial stuff allows the Leonardo+Ethernet Shield to work correctly as a web server.
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,1,177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
// Serial.begin(9600);
// while (!Serial) {}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
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");
}
}
finally it works - it was my stupid mistake not running the serial monitor. Now - without the serial statment you mentioned - it works as it should.... and sorry again!
I'd be interested to know if your Leonardo/Ethernet combo works from an independant 9v supply rather than powered from the USB.
I've just hit a very similar problem where everything works fine if the boards are powered via the usb either from the PC or an independant 5v usb supply, but try using a 9v supply into the power jack and nothing works properly. I've found that the 5v power line on the Leonardo drops to 2.2v its as though the voltage regulator on the Leonardo can't handle the extra load of the Ethernet shield!!
This sketch works happily on a Uno/Ethernet combination and has run 24/7 for two years on one installation.
I'm beginning to suspect that the Leonardo board is a Chinese clone despite the fact that it says 'made in Italy' on the back and I bought it in a shop as the genuine artical. Also the printing is slightly out of position and the labels for the extra analog inputs don't align with the supposed inputs on those pins.