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\$
1
  • \$\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.
    Commented Dec 28, 2013 at 14:28

4 Answers 4

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\$
0
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\$
2
  • 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
    Commented Apr 23, 2013 at 20:31
  • \$\begingroup\$ I'm pretty sure you can omit everything but a MAC address and use DHCP if you wanted. \$\endgroup\$
    – user28726
    Commented Dec 28, 2013 at 19:13
1
\$\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\$
3
  • \$\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
    Commented Nov 22, 2015 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
    Commented Jan 19, 2016 at 8:36
  • \$\begingroup\$ Replacing 511 resistor network worked for me. Thanks for the hint! \$\endgroup\$
    – martrah
    Commented Feb 14, 2017 at 18:52
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\$

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