Yet another IP= on Mega+W5100 question

I've been beating on this all morning... found thousands of Google responses all of which seem to point to either "make sure pin 4 is high" or "make sure your SPI pin connections are solid"...


  • Arduino UNO R3 that's brand new
  • Arduino MEGA 2560 that's a year or two old
  • W5100 ethernet shield "Mega compatible" with the 6-pin ICSP connector
  • latest (1.8?) IDE
  • Arduino Ethernet library downloaded from GitHub just a week or so ago
  • (There is no SD card installed on the shield. I do not plan to use an SD card, and (see below) I've modified the sketch to explicitly disable the SD SPI interface.)

I had to replace the RPAK on the ethernet shield (it had 510Ω instead of 51Ω) but that's fixed.


  • Arduino "DHCPAddressPrinter" Example sketch
  • Modified to force pin 4 high
  • tested both with DHCP and with a static IP address added


  • UNO + Shield: Works both DHCP and static IP -- displays a correct IP address, also functions normally with other sketches, including the one I eventually want to use (basically a web server)
  • Mega + Shield: Always reports for the IP address.
  • Checked ICSP pin connections -- continuity check board to board OK
  • Set pin 4 high. Set pin 53 to OUTPUT. Set pin 10 both HIGH and LOW. No effect.
  • Added a delay after Ethernet.begin() and before trying to print the IP. No effect.

Since the DCHPAddressPrinter sketch does nothing more than call Ethernet.begin(mac) and print the IP address, I don't know how much simpler I can make the sketch.

Note that ALL of the involved hardware is exactly the same. The ONLY thing I am changing is swapping the UNO and Mega out and recompiling/uploading the sketch for the appropriate hardware.

Threads I've already checked:

... and plenty of others... nearly all point to one of three problems, all of which I've ruled out:
(a) a bug in the W5100 library (that appears to have already been fixed by now)
(b) a poor electrical connection on the ICSP connector (nope)
(c) Not setting pin 4 high (nope).

Can you tell I'm a little bit frustrated? I've fought through a slew of hardware issues already, and now this. Please excuse the venting.

I'm hoping one/some of you can direct me to some other ideas how to resolve this? I don't have another Mega, though if it can be reasonably proven it's a hardware issue with my current Mega, I'm willing to fork out for a new one.

Thanks a bunch in advance!

Oh... FTR, here's the code, though it's the official Example only slightly tweaked:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02

// 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):
EthernetClient client;

#define IP_ADDRESS { 192, 168, 0, 42 }

void setup() {
  pinMode(53, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  // Open serial communications and wait for port to open:
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // start the Ethernet connection:
  Ethernet.begin(mac, IP_ADDRESS);
  if (Ethernet.begin(mac, ip) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
  } else {
  digitalWrite(4, HIGH);
  // print your local IP address:

void loop() {

  switch (Ethernet.maintain())
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");

    case 2:
      //renewed success
      Serial.println("Renewed success");

      //print your local IP address:

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");

    case 4:
      //rebind success
      Serial.println("Rebind success");

      //print your local IP address:

      //nothing happened


void printIPAddress()
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);


If you are using the library from Github, it is set to a w5500 by default. You must change the define in until/w5100.h

Hmm... I didn't see a define to be set anywhere in the library...

... and if I had the chipset configured wrong in the library, wouldn't it also fail on the UNO?

Is this the library you are using?

If so, you must change a define in utility/w5100.h. Change this

//#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ...
//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield 
#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet

to this. Note the define W5100 is uncommented and the W5500 is commented out.

#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ...
//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield 
//#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet

No, I'm using this one:

... which is, as I understand it, the most current version of the library that ships with the IDE.

Should I be using the Wiznet library instead? I can certainly try it.

I'm using the Wiznet library I posted a link to above with the w5100 and the define change. It's working great. I've also used the library included with the IDE, and it works ok with the w5100.

Insure the shield is connected firmly to the Arduino. Check the solder connections on the ICSP pins on the Mega. Maybe a bad solder joint or a solder bridge there.

edit: There are some older ethernet shields that do not have the ICSP connector on the bottom. That would also cause this problem. Insure it has a 2x3 plastic socket on the bottom of the shield.

Um... in the original post I specified that the shield does have the 6-pin ICSP connector, and that I had scoped out all the connections... I even reflowed the solder joints on both boards' ICSP connectors.

I also pointed out that the shield works fine with my Uno ... which verifies that the W5100 chip itself is OK... and the library is OK (unless it has a bug with Mega compatibility)

I did the resistor test you mentioned in post #32 of this thread: Ethernet Shield Not taking address - Networking, Protocols, and Devices - Arduino Forum and it indicated that the problem is with the shield, but since the shield works with the Uno, that means the problem must be in the traces between the two sets of SPI pins.

I have not been able to verify the traces on the board between the ICSP connector and the W5100 (because they run underneath the SD card socket and I can't reach the vias)...

I have some more jumper wires that should be arriving tomorrow. I will cross-wire the Ethernet board's "Uno" SPI pins (which I know work because the board works with the Uno) to the Mega's ICSP connector, to verify whether there is a problem with the traces on the board. If that works, then I will hand-rewire the ICSP connector's SPI interface.

I also have a new Mega on its way that should arrive late next week. If the problem is actually with the Mega, hopefully replacing it will help prove that out.

If the ethernet shield has the ICSP socket, it should work on the Mega. I use an ethernet shield on both the Mega and Due. The SPI pins on the shield should be on the ICSP pins only.

Yes, it should work. But it doesn't. Hence the thread.

I'll keep poking at it, maybe something will turn up.

Maybe this is the problem?

// change this
#define IP_ADDRESS { 192, 168, 0, 42 }
// to this
IPAddress IP_ADDRESS { 192, 168, 0, 42 };

Nope. Changing from #define IP_ADDRESS to IPAddress made no difference at all.

I also tried using the WIZ Ethernet library instead of the Ethernet library (with the #define in w5100.h changed as needed). Also no difference.

At this point I'm pretty sure it's got to be a hardware problem on the Ethernet shield, possibly a broken trace between the ICSP header and the w5100 chip. I have suitable jumper wires should be arriving in this evening's mail, and I will test bypassing the ICSP header on the shield, as I mentioned above. Will report back.

On newer ethernet shields, you can't bypass the ICSP connector. There are no other digital pins that are connected to the SPI bus on the shield. See the schematic for your shield.


Well, that would mean the UNO is also using the ICSP pins, right? (I have an UNO R3 with the ICSP header).

In that case, it pretty much has to be a problem with my Mega, not with the Shield, since the Shield works fine (now) with the UNO.

Well, I have a new Mega on its way, should be here later in the week.

OK, I got my new Mega in the mail this evening, and I've verified (by running the same Sketches on the new Mega with the same Ethernet Shield) that whatever was going wrong was a hardware problem on the old Mega.

I can now happily continue developing my project, and get back around to debugging the old Mega some other time.

Thanks for the help!