1
votes

Good Day Everyone.

I am having a hard time configuring the ethernet shield.

  1. I mounted the ENC28J60 Ethernet Shield on the Arduino Mega 2560.
  2. I connected the USB port of the Arduino to the USB port of my PC,
  3. I connected the ethernet port of the Ethernet Shield to a LAN Port of a TP-Link Router with an IP Address of 192.168.0.1 and has a DHCP starting address from .100 to .200

I put uploaded the code that I get from to the Arduino Module: https://www.arduino.cc/en/Reference/EthernetClient

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


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 100 };
byte server[] = { 64, 233, 187, 99 }; // Google

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

And then, from the serial window of Arduino IDE, I am getting

connecting... connection failed disconnecting...

I also tried some similar codes from above, some are outputting the shields IP, but still, I get the same problem, the Ethernet Shield does not output an IP Address or says "connected".

I also tried both straight-through and cross-over cables.

Please Help.

Thanks.

2

2 Answers

0
votes

In your code:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

Must match your Ethernet Shield mac address.

0
votes

Maybe try letting your router provide an IP address via DHCP. To do that, just change the line in your setup routine to Ethernet.begin(mac);