Ethernet Example LAN8720 with ESP32 ETH01 module not working

I have WT32 - ETH01 ESP32 module with me, and am just trying it to connect to the internet, but basic example code of LAN8720 is not working. am getting error lines as below,

13:11:28.681 -> E (1010) esp.emac: emac_esp32_init(371): reset timeout
13:11:28.681 -> E (1010) esp_eth: esp_eth_driver_install(228): init mac failed

can Anyone help me here to resolve the issue

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in https://forum.arduino.cc/c/using-arduino/uncategorized/184.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.

have a look at wt32-eth01
using HelloServer

// for ESP32-ETH01 
/*
 * HelloServer example from the ESP32 WebServer library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <WebServer.h>
#include <ESPmDNS.h>

//W5500Driver driver;
//ENC28J60Driver driver;
//  EMACDriver(EthPhyType phyType, int mdcPin = 23, int mdioPin = 18, int powerPin = -1, emac_rmii_clock_gpio_t clockPin = EMAC_APPL_CLK_OUT_GPIO, emac_rmii_clock_mode_t clockMode = EMAC_CLK_EXT_IN);
EMACDriver driver(ETH_PHY_LAN8720, 23, 18, 16);   // note powerPin = 16 required

WebServer server(80);

const int led = 35;//13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp32!");
  digitalWrite(led, 0);
}

void handleNotFound() {
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);

  Serial.begin(115200);
  delay(500);
  while (!Serial);

  Ethernet.init(driver);

  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin()) {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  } else {
    Serial.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  delay(2);  //allow the cpu to switch to other tasks
}

serial monitor displays

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.66
MDNS responder started
HTTP server started

and Firefox wseb client displays
image

post your code?

Hi horace, thanks for replying, i am pasting my code here,

#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_ADDR 0
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER -1
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
//#endif

#include <ETH.h>

static bool eth_connected = false;

// WARNING: onEvent is called from a separate FreeRTOS task (thread)!
void onEvent(arduino_event_id_t event) {
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
// The hostname must be set after the interface is started, but needs
// to be set before DHCP, so set it from the event handler thread.
ETH.setHostname("esp32-ethernet");
break;
case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.println("ETH Got IP");
Serial.println(ETH);
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_LOST_IP:
Serial.println("ETH Lost IP");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default: break;
}
}

void testClient(const char *host, uint16_t port) {
Serial.print("\nconnecting to ");
Serial.println(host);

NetworkClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}

Serial.println("closing connection\n");
client.stop();
}

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("event start");
Network.onEvent(onEvent);
delay(5000);
Serial.println("Begin start");
ETH.begin();
Serial.println("Begin done");
delay(5000);
}

void loop() {
if (eth_connected) {
testClient("google.com", 80);
}
delay(10000);
}

Also, I tried your code now, its asking for
#include <EthernetESP32.h>
#include <WebServer.h>
#include <ESPmDNS.h>
files, do u have those package?


also in Example code of Hello Server I tried but it also error with below line,
18 | #include <WebServer_WT32_ETH01.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: WebServer_WT32_ETH01.h: No such file or directory

Code is below:

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4
#define ETHERNET_WEBSERVER_LOGLEVEL 3

#include <WebServer_WT32_ETH01.h>

WebServer server(80);

// Select the IP address according to your local network
IPAddress myIP(192, 168, 0, 132);
IPAddress myGW(192, 168, 0, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

void handleRoot()
{
String html = F("Hello from HelloServer running on ");

html += String(BOARD_NAME);

server.send(200, F("text/plain"), html);
}

void handleNotFound()
{
String message = F("File Not Found\n\n");

message += F("URI: ");
message += server.uri();
message += F("\nMethod: ");
message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += server.args();
message += F("\n");

for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}

server.send(404, F("text/plain"), message);
}

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial);

// Using this if Serial debugging is not necessary or not using Serial port
//while (!Serial && (millis() < 3000));

Serial.print("\nStarting HelloServer on " + String(ARDUINO_BOARD));
Serial.println(" with " + String(SHIELD_TYPE));
Serial.println(WEBSERVER_WT32_ETH01_VERSION);

// To be called before ETH.begin()
WT32_ETH01_onEvent();

//bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO,
// eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
//ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);

// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
ETH.config(myIP, myGW, mySN, myDNS);

WT32_ETH01_waitForConnect();

server.on(F("/"), handleRoot);

server.on(F("/inline"),
{
server.send(200, F("text/plain"), F("This works as well"));
});

server.onNotFound(handleNotFound);

server.begin();

Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(ETH.localIP());
}

void loop()
{
server.handleClient();
}

Please use code tags, the symbol. Autoformat the code in the IDE first.

In short install library WebServer_WT32_ETH01 and try the examples included ( those specific of the library as MQTT_And_OTA_Ethernet ) they work for me.

Last week I tried also aws iot connection and it works reliably, so I can say I like the board ( even if it does not include the 'usb connector' )

NOTE
You can install the library directly from the ide library manager.
Don't know if relevanet... but I'm using ide 1.8.19, esp32 board package 2.0.13

lets not mix everything together.

  1. WebServer_WT32_ETH01 is for esp32 platform version 2 and is obsolete.

  2. the ETH_LAN8720.ino example use the platform's Ethernet library and it should work. until that is not working, nothing else will

  3. EthernetESP32 is my a-common-arduino-user friendly alternative to platforms Ethernet library

so make the ETH_LAN8720 example work by using the right settings

using the library manager install EthernetESP32

and try File>Examples>EthernetESP32>HelloServer

install any other libraries required

In that case, I dont know am trying to run it directly the eth example, Am i Missing something? could you share your code i will compare what i missed?

my code:

#define ETH_PHY_TYPE  ETH_PHY_LAN8720
#define ETH_PHY_ADDR  0
#define ETH_PHY_MDC   23
#define ETH_PHY_MDIO  18
#define ETH_PHY_POWER -1
#define ETH_CLK_MODE  ETH_CLOCK_GPIO0_IN
//#endif

#include <ETH.h>

static bool eth_connected = false;

// WARNING: onEvent is called from a separate FreeRTOS task (thread)!
void onEvent(arduino_event_id_t event) {
  switch (event) {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      // The hostname must be set after the interface is started, but needs
      // to be set before DHCP, so set it from the event handler thread.
      ETH.setHostname("esp32-ethernet");
      break;
    case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.println("ETH Got IP");
      Serial.println(ETH);
      eth_connected = true;
      break;
    case ARDUINO_EVENT_ETH_LOST_IP:
      Serial.println("ETH Lost IP");
      eth_connected = false;
      break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default: break;
  }
}

void testClient(const char *host, uint16_t port) {
  Serial.print("\nconnecting to ");
  Serial.println(host);

  NetworkClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    return;
  }
  client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
  while (client.connected() && !client.available());
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("closing connection\n");
  client.stop();
}

void setup() {
  Serial.begin(115200);
  Network.onEvent(onEvent);
  ETH.begin();
}

void loop() {
  if (eth_connected) {
    testClient("google.com", 80);
  }
  delay(10000);
}

select all code and click the < CODE/ > button; next save your post. This will make the code easier to read, easier to copy and the forum software will display it correctly.

1 Like

I found:
https://github.com/egnor/wt32-eth01?tab=readme-ov-file#using-ethernet

That oscillator is enabled by setting GPIO 16 high

so set pin 16 HIGH before ETH.begin

okay I did, but i get below errors now,

17:24:49.893 -> E (1120) eth_phy_802_3: esp_eth_phy_802_3_pwrctl(250): power up timeout
17:24:49.939 -> E (1120) eth_phy_802_3: esp_eth_phy_802_3_basic_phy_init(433): power control failed
17:24:49.939 -> E (1123) lan87xx: lan87xx_init(341): failed to init PHY
17:24:49.939 -> E (1128) esp_eth: esp_eth_driver_install(229): init phy failed

using your code of post 10 modified so

#define ETH_PHY_TYPE ETH_PHY_LAN8720
//#define ETH_PHY_ADDR 0      // commented out
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
//#define ETH_PHY_POWER -1    // commented out
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN

and

void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println("\n\nESP32-ETH01 <ETH.h> library");
  pinMode(16, OUTPUT);     // set pin to output
  digitalWrite(16, HIGH);  // turn on power
  delay(1000);
  Network.onEvent(onEvent);
  ETH.begin();
}

Tools>Board set to WT32-Ethernet the serial monitor displays

ESP32-ETH01 <ETH.h> library
ETH Started
ETH Connected
ETH Got IP
*eth0: <UP,100M,FULL_DUPLEX,AUTO,ADDR:0x1> (DHCPC,GARP,IP_MOD)
      ether E8:6B:EA:D8:2F:43
      inet 192.168.1.72 netmask 255.255.255.0 broadcast 192.168.1.255
      gateway 192.168.1.254 dns 192.168.1.254

connecting to google.com
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-7fH2Y5G1GPV56_C-3aCwpQ' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Date: Sun, 28 Jul 2024 12:17:53 GMT
Expires: Tue, 27 Aug 2024 12:17:53 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
closing connection


try ETH_PHY_ADDR 1 or ETH_PHY_ADDR -1

Hi @horace, Great it worked, with this changes you said thank you so much for the timely support !!! :blush:

My aim here is to calculate the speed of the network, but in the starting of connecting to the internet itself i got stuck, now its connected...

by the way do you have any idea? is there any api available for checking the internet speed in that LAN?

when compiled the original code of post 10 gives two warning

F:\Ardunio\Networking\WiFi\ESP32\ESP32-ETH01\ETH_H library\Connect_to_Google_server\Connect_to_Google_server.ino:2: warning: "ETH_PHY_ADDR" redefined
    2 | #define ETH_PHY_ADDR 0      // commented out
      | 
In file included from C:\Users\bb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\cores\esp32/esp32-hal-gpio.h:29,
                 from C:\Users\bb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\cores\esp32/esp32-hal.h:75,
                 from C:\Users\bb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\cores\esp32/Arduino.h:36,
                 from C:\Users\bb\AppData\Local\Temp\arduino\sketches\ECC16C54B028EF1671C507F066ACFD5C\sketch\Connect_to_Google_server.ino.cpp:1:
C:\Users\bb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\variants\wt32-eth01/pins_arduino.h:13: note: this is the location of the previous definition
   13 | #define ETH_PHY_ADDR  1
      | 
F:\Ardunio\Networking\WiFi\ESP32\ESP32-ETH01\ETH_H library\Connect_to_Google_server\Connect_to_Google_server.ino:5: warning: "ETH_PHY_POWER" redefined
    5 | #define ETH_PHY_POWER -1    // commented out
      | 
C:\Users\bb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\variants\wt32-eth01/pins_arduino.h:14: note: this is the location of the previous definition
   14 | #define ETH_PHY_POWER 16
      | 

commenting out the defines removes the warnings

why it is a good idea to have warnings enabled and to read them!

@horace, you have a different sketch. OP has the example of the platform's Ethernet library