3
\$\begingroup\$

I have an Arduino Ethernet shield on top of an Arduino Mega2560 and have connected the Mega2560 through serial to my laptop and through the UTP port on the Ethernet shield to my router.

I've tried the "search Arduino on Google" example (where I corrected Google's IP address, the example was old), and it doesn't work (it doesn't seem to connect to the Internet. On the serial, I get: "connecting... /connection failed / disconnecting.").

My UTP cable is working fine... I've tested it on my laptop.

The Mega2560 is connected to my router (which has everything disabled so that's not the problem ) and when I ping from my laptop the IP address I gave the Arduino assembly, it doesn't ping back.

Why? Maybe there is something I'm missing? Here is my code:

Code:

#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 };
byte server[] = { 209,85,148,147 }; // Google

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);

void setup() {
  // Start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // Start the serial library:
  Serial.begin(9600);
  // Give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // If you get a connection, report back via serial:
  if (client.connect()) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  }
  else {
    // If you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // If there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // If the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // Do nothing forevermore:
    for(;;)
      ;
  }
}
\$\endgroup\$
  • \$\begingroup\$ What is the "revision" # of both the Mega and the Ethernet shield (excuse me, daughterboard)? As another post suggests, there was a pin change between revisions - I believe the latest is R3. I regularly use an R3 Ethernet shield with R3 Mega256 boards without any issues. \$\endgroup\$ – Ron J. Dec 28 '13 at 14:28
2
\$\begingroup\$

The Arduino uses SPI to communicate between the devices. Since the design of the Arduino Mega changed and the older pinout relates to older shields, in order to use it with newer shields you have to hack it a little, to work around the problem.

A lot of people had this question before, and you can still find the answer here: http://mcukits.com/2009/04/06/arduino-ethernet-shield-mega-hack/

\$\endgroup\$
2
\$\begingroup\$

enter image description here

Check the Ethernet socket on the back road of resistance row, normal value shall be 510 (51Ω)

If it is 511 (510Ω) is a hardware error, replace the normal operation of the correct resistor

\$\endgroup\$
  • \$\begingroup\$ My Ethernet shield is not working, and it have this this 511, is the board defect then, should i get it replaced? \$\endgroup\$ – Androme Nov 22 '15 at 8:57
  • \$\begingroup\$ Thanks for the hint (500 R instead of 50R). This may solve my problem, because in some combinations it works and in some not and till now I got no explanation for that. It seems that with the wrong termination the signal integrity is close to the border. \$\endgroup\$ – user97560 Jan 19 '16 at 8:36
  • \$\begingroup\$ Replacing 511 resistor network worked for me. Thanks for the hint! \$\endgroup\$ – martrah Feb 14 '17 at 18:52
1
\$\begingroup\$

For connecting to a server outside your network, you need to include the gateway in Ethernet.begin:

byte dns[] = {8,8,8,8};
byte gateway[] = {192,168,1,1};
Ethernet.begin(mac,ip,dns,gateway);
\$\endgroup\$
  • 3
    \$\begingroup\$ The gateway address is optional, as it defaults to the IP address with the last octet set as 1. (If your Arduino's ethernet address is 192.168.10.23, the default gateway is expected to be 192.168.10.1)(Same for Subnet mask defaulting to /24). It only needs to be included if the gateway is different from the expected default. \$\endgroup\$ – Passerby Apr 23 '13 at 20:31
  • \$\begingroup\$ I'm pretty sure you can omit everything but a MAC address and use DHCP if you wanted. \$\endgroup\$ – user28726 Dec 28 '13 at 19:13
0
\$\begingroup\$

Well, in my case the arduino won't communicate because there is a problem with auto negotiation of 10/100mb.

So, I set it to 10mb. And, them it communicate.

I try to use a cat3 cable and it works in same cases. So I decided to use a router where i can set it to 10mb.

Best regards.

\$\endgroup\$

protected by Dave Tweed Feb 14 '17 at 20:28

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.