Problem with Ethernet library

Hello everyone
I have successfully tested ping connection between enc28J60 with Arduino mega using UIPEthernet library. But for my project I need to call API so I found this link https://arduinogetstarted.com/tutorials/arduino-http-request

But this tutorial use different library "Ethernet" so I wanted to try that one

I tried few sketch https://www.arduino.cc/reference/en/libraries/ethernet/

#include <SPI.h>
#include <Ethernet.h>
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 192, 168, 20, 20 };    

void setup()
{
  Ethernet.begin(mac, ip);
  Ethernet.localIP();
  Serial.println( Ethernet.localIP());
}

void loop () {}

It doesn't print valid IP address It show 0.0.0.0

anyone are using this specific library. I don't understand what's wrong with it?

Tell us about your hardware, the wiring, the network… does the IP make sense?
Does begin() succeed?

Ethernet Module and my laptop is connected to switch using lan cable. switch is connected with router All devices are in same network

wiring

Enc28j60	Arduino Mega 2560
GND	              GND
5V	              5V
SO	              Pin50
SI	              Pin51
SCK	              Pin52
CS	              Pin53

try IPAddress ip(192, 168, 20, 20);

It doesn't work

#include <SPI.h>
#include <Ethernet.h>
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
IPAddress ip(192, 168, 20, 20);

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

void loop () {}

This IP doesn't make any sense
15:37:42.883 -> 0.0.0.0

it means it failed even before it could set the IP.
run the WebClient example. it has enhanced diagnostics.

You seem to be trying the Ethernet library on the Enc28j60.
You can't. The Ethernet library works with the WizNet chips that have the TCP/IP library built in. The Enc28j60 doesn't have the TCP/IP library built in so all of the TCP/IP stuff is done in the UIPEthernet library. That's why the library is so large.

You can either go back to the UIPEthernet library or get an Ethernet Shield with a WizNet chip:

@johnwasser EthernetENC is the new UIPEthernet (I maintain both., I missed that OP has an enc28j60)

1 Like

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