Connecting ESP32 to Ethernet Shield 2

Hello,

I'm trying to connect my ESP32-WROOM-32D to the Arduino ethernet shield 2. I use the Ethernet Shield Web Client example code with Ethernet.init(5);. This is my wiring:

Name Ethernet Shield esp32
SPI_CS (SS) 10 5
SPI_MOSI ICSP MOSI 23
SPI_MISO ICSP MISO 19
SPI_SCK ICSP SCK 18

It seems that the esp32 doesn't recognize the ethernet shield, since I get the output:

Ethernet shield was not found. Sorry, can't run without hardware. :(

Does anyone know if or how you can connect an esp32 to the arduino ethernet shield 2?

My main questions are:

  • Is my wiring correct? (SPI wired correctly?, GND and 5V wired correctly? Do I need RESET?)
  • Do I use the right library? (I am using the standard Arduino Ethernet library, but have modified it as suggested here)
  • Is the Arduino Ethernet Shield 2 compatible with the ESP32 at all?

Thank you in advance!

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;  // set to false for better speed measurement

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
  Ethernet.init(5);

  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.print("connecting to ");
  Serial.print(server);
  Serial.println("...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  beginMicros = micros();
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  int len = client.available();
  if (len > 0) {
    byte buffer[80];
    if (len > 80) len = 80;
    client.read(buffer, len);
    if (printWebData) {
      Serial.write(buffer, len); // show in the serial monitor (slows some boards)
    }
    byteCount = byteCount + len;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    endMicros = micros();
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.print("Received ");
    Serial.print(byteCount);
    Serial.print(" bytes in ");
    float seconds = (float)(endMicros - beginMicros) / 1000000.0;
    Serial.print(seconds, 4);
    float rate = (float)byteCount / seconds / 1000.0;
    Serial.print(", rate = ");
    Serial.print(rate);
    Serial.print(" kbytes/second");
    Serial.println();

    // do nothing forevermore:
    while (true) {
      delay(1);
    }
  }
}
Schematic


Edits
  • Corrected mistake: Ethernet.init(5); instead of Ethernet.init(33);
  • Changed wiring. Juraj pointed out, that the Ethernet Shield doesn't use the pins 11, 12, 13, but the ICSP header pins. I changed my wiring accordingly, but it still doesn't work. Old wiring:
    Name Ethernet Shield esp32
    SPI_CS(SS) 10 5
    SPI_MOSI 11 23
    SPI_MISO 12 19
    SPI_SCK 13 18

Welcome to the forum

The ESP32 is a 3.3V device. What voltage does the shield run at ?

In the W5500 datasheet it says:

3.3V operation with 5V I/O signal tolerance

I connected the GND of the esp32 to the GND of the shield and the 5V pin of the esp32 to the 5V pin of the shield. At least a green LED lights up on the shield, so I assume that it is powered.

why? your CS pin is 5

the Ethernet shield doesn't have MOSI, MISO, SCK on pins 11, 12, 13. they are on the SPI header

My mistake, I tried both Ethernet.init(5); and Ethernet.init(33); with according wiring, but neither worked.

Thank you, this could be the problem. Because of this schematic, I thought that the Ethernet shield would use the pins 11, 12 and 13. I will try to connect my esp32 with the ICSP header pins of the shield.

I connected the esp32 with the ICSP header pins, but it still doesn't work:

See EthernetShield_Breadboard, EthernetShield_Schematic

what esp32 model do you have and select in Tools menu?

I selected the board "ESP32 Dev Module".

Has the OP loaded up a simple blink the on-board LED to see if the ESP32 works?

try lower frequency in w5100.h spi settings

Yes, my Esp32 works. I was already able to measure the temperature and send it our server via WiFi, but I want to connect it to Ethernet, because I can't rely on the WiFi to be stable.

the esp32 arduino WiFi library supports LAN8720 Ethernet
https://github.com/espressif/arduino-esp32/tree/master/libraries/Ethernet/examples/ETH_LAN8720

I will try this, if I have no other option, but the description of how to connect this LAN8720 to the ESP32 sound rather scary: Ethernet on ESP32 using LAN8720 (sautter.com). If it is possible, I would like to use the Arduino Ethernet shield that I already have.

Did u solve the issue with the EthernetShield2?

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