I'm a newb to the Arduino and having a few issues pinging the a W5100 Ethernet Shield X1 I purchased off of eBay, it looks just like the one on the Arduino site with a few silkscreen differences. I'm using it with a Mega2650. The Ethernet shield didn’t have a sticker on it listing its MAC address so I'm assuming its not fixed. I have been using the web server example and have set the IP address to a unused one on my router. I used the stock MAC address from the example and tried some off the wiznet site but sill can't ping the shield.
Does this shield just plug into the mega board or do I have to rewire it? the board says it's mega compatible.
Is there any way to tell if it’s a newer board that that a fixed MAC address? there is no label on it.
if it has a fixed MAC address is there a way to find out what it is?
Is there a way to tell if the board are talking to each other?
Any help would be greatly appreciated. thanks, Mike
Can you post the code you are using?
Problem with the Mega and the Ethernet shield is that the SPI pins aren't on the same position as on the UNO and 2009. So, unless you have the ICSP connection made between the shield and the board, a standard example won't work.
If you can post the code and a picture of your setup it could help a bit more.
My Mega2560 and the ethernet shield work fine. If you program it correctly, it should respond to a ping. That is the best way to troubleshoot it . Once it responds to a ping, you can work on the other stuff.
Like bubulindo asked, maybe if you posted your code we could help.
This is the basic code required to get the ethernet shield to respond to a ping. Change the ip and gateway to your setup. Then try another ping. I use a LED "heartbeat" to insure the code is running. The pin 13 LED should blink once a second.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
byte ip[] = { 192, 168, 2, 2 };
byte gateway[] = { 192, 168, 2, 1 };
byte subnet[] = { 255, 255, 255, 0 };
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(13,OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
}
Add: The subnet mask is important also. It determines the localnet broadcast address. Without it, the ethernet shield and the router may not communicate well.
Thanks for the quick replies. im using the code from the web sever example, it doesn't include a subnet so I will try the code you posted but need to wait till tonight to get to my Arduino. do you just have the Mega and the shield plugged together? or rewired to pins 50-53. im guessing it uses the ICSP connector so can just be plugged together. thanks! I hope I inserted the code correctly i followed the directions but doesn't preview well.
Code
/*
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 4 Sep 2010
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 };
byte ip[] = { 192,168,1, 177 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// 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();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
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();
}
}
Mine is stock. The ethernet shield plugs into the Mega just like it should on a Uno, except the mega protrudes from the rear a bit. The ethernet shield socket should fit over the ICSP pins, correct?
Use both the gateway and the subnet on the ethernet setup. Try that test I posted, just to be sure. It should only take a minute.
thanks SurferTim, the connector fits over the ISCP connector and just in case i buzzed it out with a meter. I loaded your code, left all the defaults(they should work with my router) the led flashes but still no reply to ping. Im wondering if my shield is bad.
What Ethernet cable are you using?
Have you tested that?
If replacing the cable doesn't help (try that first), then you might need to fix an error in your version of Arduino. I had to patch mine to get it working.
This thread covers the error.
http://arduino.cc/forum/index.php/topic,68624.0.html
I would not presume the card is bad yet. If the ethernet shield was not responding to the SPI commands, it would have failed in the startup. In that case the LED would not blink.
The router/switch ethernet port lights are on also?
And nothing else is connected to the Arduino or the shield, correct? Nothing connected to pins 10-12.
Add: Your localnet is 192.168.2.0/24?
No other 192.168.2.2 ip on that network?
What is the ip of the computer you are using for the ping attempt?
I have tried 2 cables and plugged in another computer to test the cable. I will try the patch. the leds light and flash but they do that even if I just load the blink sketch. I have loaded the Web Server example with out the shield plugged in and it loaded fine so I don't think the Arduino knows if the shield is connected or not. the flashy led is driven by the Arduino's output 13 so I think it would flash ether way.
thanks again!
I just checked the ethernet shield, and you are correct. It runs Ethernet.begin() apparently without error even with no shield connected.
Blink, blink, blink... ??
I was certain I had checked that. I'll try to take a look at the code and see if I can figure out why.
Let me know how the patch does.
No luck with the patch.
There is no error checking on the ethernet shield functions. It doesn't care if there is an operational shield connected or not.
Wouldn't it be great if the init routine worked like this?
if(Ethernet.begin(mac, ip, gateway, subnet))
{
Serial.println("Ethernet shield ok");
}
else
{
Serial.println("Ethernet shield error");
}
Mine does now. It requires only minor mods to w5100.h, w5100.cpp, ethernet.h and ethernet.cpp. I attached those files if you are interested in trying it. The w5100.h file also has the ethernet 16 bit register fix.
The ethernet files are in /arduino/libraries/Ethernet/
and the w5100 files are in /arduino/libraries/Ethernet/utility/
w5100.cpp (3.78 KB)
w5100.h (13.1 KB)
Ethernet.cpp (956 Bytes)
Ethernet.h (535 Bytes)
Wow your putting a lot of work into this, thank you so much!
Ok so just to make sure were on the same page. I need to replace the 4 files with the ones you gave me. I tried to cut and paste the ethernet ok code into the sketch you gave me but had some errors, im just coming up to speed on the whole programming thing.
Thanks, but compared to the previous work on the ethernet shield, this was easy. I am trying to get it to the point it is easier to troubleshoot without adding a lot of code.
What errors are you getting?
The four files I posted need to be placed in those directories. Then you can use the code I posted above.
ethernet.h and ethernet.cpp go in /arduino/libraries/Ethernet/
w5100.h and w5100.cpp go in /arduino/libraries/Ethernet/utility/
This is the only code that was added. This is in w5100.cpp. The other changes were changing void return type functions to uint8_t return functions to pass that value back to Ethernet.begin(). It reads a register value that was just written to the ethernet shield. If the shield returns 0x55, the SPI and the shield are working (returns 1). If it returns anything else, failure (returns 0).
if(readTMSR() == 0x55)
{
return 1;
}
return 0;
I have reply! I changed the IP address to 192.168.0.XXX from 192.168.1.XXX and it's talking. I thought that was a valid ip not sure why it did work. The code you made up should be in the next release it would have been a great help to know if the boards were even talking. thank you very much for all your help.
I thought that was a valid ip not sure why it did work.
If you are connecting your arduino to a router, you need to use an address similar to the router. Are you using a D-Link router?
It's a Rosewill and I also tried my linksys E4200. the Rosewill's IP Address is 192.168.0.1
the Rosewill's IP Address is 192.168.0.1
Linksys routers I think use the same. Netgear routers (and maybe also D-link) use 192.168.1.1 as their IP address. I think these can be easily changed in the router setup if desired.
That was a valid ip, just not for your localnet. If the ip for the router is 192.168.0.1 and the subnet is 255.255.255.0, then the only ip ranges recognized on that localnet will be 192.168.0.1 to 192.168.0.255. All other ip requests will be sent to the gateway ip (192.168.0.1).
That is where any ip that is out of your localnet is sent. When you tried to ping 192.168.1.x or 192.168.2.x ips, they were sent to the router, and it did not know where to send the packets. So it forwarded them to its gateway (public subnet/internet?).
That was the reason for my questions in reply #7.
Add: Your localnet is 192.168.2.0/24?
No other 192.168.2.2 ip on that network?
What is the ip of the computer you are using for the ping attempt?
FYI: If you use the Ethernet.begin(mac,ip) instead of Ethernet.begin(mac,ip,gateway,subnet), it adds 255.255.255.0 as the subnet and your gateway is made by using the first three sets of ip numbers and the fourth is a '1'. So if your ip was 192.168.0.2, then it would set the gateway to 192.168.0.1
Have you checked the MAC table on the PC/Router.
This should contain the MAC address if the arduino has tried some kind of connection to on the network.
In troubleshooting arduino ethernet connectivaty this is the first place to look.
On windows: arp -a