Can't ping Arduino Mega with Ethernet 2 shield

Hey you dears,

I'm new in arduino stuff and not familiar with network connections and settings.
I want to etablish a modbus communication similar to this tutorial:

I also need a static IP address for my arduino, so I tried this sketch:

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

// replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x87, 0xB8};

// change the IP address, subnet mask, gateway's IP address, and DNS server's IP address depending on your network
IPAddress ip(192, 168, 56, 3);
IPAddress gateway(192, 168, 56, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress myDns(8, 8, 8, 8);

// TODO: Declare something depending on your application

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

  // initialize the Ethernet shield using the static IP address:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);

  // TODO: initialize something depending on your application
}

void loop() {
  // optional, check link status
  if (Ethernet.linkStatus() == LinkON)
    Serial.println("Link status: On");
  else
    Serial.println("Link status: Off");

  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  
  // TODO: do something depending on your application
}

but I couldn't ping the Address I gave the arduino.

Maybe someone can help me?

I tested it plugged directly with an ethernet cable to the PC.
The shield seems to be connected and the cable seems to work. This is what the serial monitor shows:
serial monitor

But if I try to ping the IP address it couldn't be found:

This is the stuff I got if i try ipconfig:

I have no idea, what could be the problem.
Maybe someone can help me.

Thanks a lot,
sipmpli.

PS: sorry for the many posts, but I just can upload one picture per message.

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Are you using the Ethernet connector on the PC? It looks like that interface has a self-assigned address (169.254.42.96) so it isn't on the same subnet as your Arduino.

I would try assigning your PC's Ethernet interface an IP address like 192.168.1.1 and moving your Arduino to the 192.168.1.x network.

1 Like

Thanks a lot!

That was the solution. First the Ethernet Adapter didn't take the IP address we gave it, so we decided to change the IP address of the arduino to the subnet of the adapter and it worked!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.