Ethernet Shield 2 woes. Cannot get it working no matter what I try.

Issue: No examples or online tutorials will work when I try to access the Arduino via Ethernet. For example, the DHCPChatServer:

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac = {
0xA8, 0x61, 0x0A, 0xAE, 0x0E, 0x5D
};
IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection:
Serial.println(“Trying to get an IP address using DHCP”);
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// initialize the ethernet device not using DHCP:
Ethernet.begin(mac, ip, gateway, subnet);
}
// print your local IP address:
Serial.print(“My IP address: “);
ip = Ethernet.localIP();
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(ip[thisByte], DEC);
Serial.print(”.”);
}
Serial.println();
// start listening for clients
server.begin();

}

void loop() {
// wait for a new client:
EthernetClient client = server.available();

// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println(“We have a new client”);
client.println(“Hello, client!”);
gotAMessage = true;
}

// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.print(thisChar);
}
}

When I input http://192.168.1.177, I only get “This site can’t be reached”. Same thing for any other example or code online I try.

Hardware Setup: Arduino Mega with Ethernet Shield V2 plugged into a Netgear AC750 router (also have tried a Netgear FS108 Ethernet switch, no luck). My computer is also connected to the same router via Ethernet.

So, here’s what I’ve tried:

When I use the Ethernet2 library, serial stays stuck on “Trying to get an IP address using DHCP”

When I use the Ethernet library, serial stays stuck on “Trying to get an IP address using DHCP
Failed to configure Ethernet using DHCP
My IP address: 0.0.0.0.”

I’ve run the SPI test SurferTim has posted to check the SPI connection:

#include <SPI.h>
#include <Ethernet2.h>

byte mac = { 0xA8, 0x61, 0x0A, 0xAE, 0x0E, 0x5D };
IPAddress ip(192,168,2,2);

void setup() {
Serial.begin(9600);

// disable SD card if one in the slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

Serial.println(“Starting w5500”);
Ethernet.begin(mac,ip);

Serial.println(Ethernet.localIP());
}

void loop() {
}

The output I get is “Starting W5500
192.168.2.2”

The DHCPAddressPrinter usually does not give me an output. I’ve occasionally got an IP address to output, but it seems random whether or not it works. Usually, it just times out & says it failed to configure.

I’ve tried multiple different shields & boards. Connection is good. What am I doing wrong?

the chat servers listens on telnet port 23. use telnet client

use the Ethernet library, not the Etherne2

I actually tried port 23 as well, forgot to mention that. I've tried 80, 80801, 8082, & 23.

I'll try the plain Ethernet library & report back. From everything I've read, Ethernet doesn't work with the 5500s?

milanschreiber: I'll try the plain Ethernet library & report back. From everything I've read, Ethernet doesn't work with the 5500s?

that was true before 8/2018

Alright, so I've gone back & tried everything with the Ethernet Library, rather than Ethernet2. Is there some sort of update I need to manually be doing to Ethernet? I just installed the IDE on this laptop this week, so it should be up to date. The only library my manager said has an update available is the Adafruit one.

The SPI test printed the given IP, so that connection is fine.

When I try to run DhcpAddressPrinter, only change to the example code is my shield's MAC address, I get the Serial output:

Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
Ethernet shield was not found.  Sorry, can't run without hardware. :(

I tried unplugging the shield, re-running, & got the same message. Plugged the shield back in (very securely, checked multiple times) & I still get the same error. Even tried applying some downwards pressure in a third run in case pins weren't making total contact.

I tried loading the Ethernet2 example for DhcpAddressPrinter. Rather than the missing hardware message, I get no serial output for 2 minutes, than a "Failed to configure Ethernet using DHCP" message.

~`~

After switching out the shield for a different one, I can get the DhcpAddressPrinter to print an IP address 192.168.1.3

I can ping this IP address & see it on my IP scanner, so I know the computer definitely sees it on the network.

So, now I'm trying DhcpChatServer. I replaced the MAC address with the one on my (new) shield, & the IP address with 192.168.1.3. According to ipconfig, my Ethernet LAN default gateway is 192.168.1.1 & my subnet is 255.255.255.0.

Here are my IP settings in the code:

IPAddress ip(192, 168, 1, 3);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

After uploading, I get serial output:

Trying to get an IP address using DHCP
My IP address: 192.168.1.3

However, when I try to visit http://192.168.1.3:23 in my browser, it still tells me this site can't be reached. I also tried just http://192.168.1.3 & http://192.168.1.3:80 for good measure.

I have absolutely no idea what's going on at this point. It should be working, right?

use the WebServer example if you can't test with telnet client

Juraj: use the WebServer example if you can't test with telnet client

Well, there's progress, but interesting results.

My initial serial output is:

gned-ex⸮⸮Ethernet WebServer Example
Ethernet cable is not connected.
server is at 192.168.1.3

The Ethernet cable is definitely connected, I'm not sure why I'm getting that initial message.

When I visit http://192.168.1.3, I get the following in my browser:

analog input 0 is 457
analog input 1 is 475
analog input 2 is 994
analog input 3 is 1023
analog input 4 is 746
analog input 5 is 605

I also get this serial output that keep repeating:

new client
GET /favicon.ico HTTP/1.1
Host: 192.168.1.3
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://192.168.1.3/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

client disconnected

If I input 3.3V to an analog pin, that pin's value is updated to 711 on the next serial refresh.

~`~

So, it looks like I'm mostly working now, thanks! But why does this example work, while the DhcpChatServer does not?

The "Ethernet cable is not connected" message is concerning as well. Looking at the code:

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");

I recall seeing that the Ethernet library didn't support Ethernet.linkStatus, or something along those lines. is that still the case?

milanschreiber: So, it looks like I'm mostly working now, thanks! But why does this example work, while the DhcpChatServer does not?

The "Ethernet cable is not connected" message is concerning as well. Looking at the code:

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");

I recall seeing that the Ethernet library didn't support Ethernet.linkStatus, or something along those lines. is that still the case?

do you know what is a telnet client?

linkStatus is new in the latest version

I'm not exactly clear on what telnet is, even after reading a bit about it.

I was able to get an example code for Ethernet control of an led working, but when I tried modifying it, it's telling me my server is at 0.0.0.0 now. I made a separate post here about it, if you'd be inclined to check it out :) Thanks!

the DhcpChatServer example

arduino_telnet.png