Possible? Yes. Simple? Oh no. The ESP-IDF example makes a modification to the SDK settings (here). The Arduino uses a precompiled version of the SDK with this setting set the opposite way. So, integrating it into Arduino-ESP32 would require a recompilation of the base libraries which I presonally found to be extremely tedious (GitHub - espressif/esp32-arduino-lib-builder).
The ENC28J60 is a very common Ethernet chip with good general library support. Do the libraries linked at Ethernet test on esp32 not work?
The library is a supplement for Ethernet.h that would usually be used for the e.g. Arduino AVR core. Hence, all sketches like Ethernet/examples at master · arduino-libraries/Ethernet · GitHub should work with it. As a starting point, you can e.g. use WebClient.ino, with the Ethernet.init(x); line adapted for x = Chip Select pin to the W5500 module.
Sorry yes, I misspoke, the jandrassy/EthernetENCis for the ENC28J60, it is the “usual” Arduino-provided Ethernet.h library that’s implemented for W5500 (and similiar) chips. But the EthernetENC library is exposing the same APIs as the usual Arduino library, just under the hood it’s having the code to talk to a ENC28J60 chip. So yes, you can use those examples.
#include <SPI.h>
#include <EthernetENC.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server_ethernet(80);
EthernetClient client_ethernet;
// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true; // set to false for better speed measurement
void Ethernet_Init(void)
{
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(15); // Most Arduino shields
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// 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.");
}
// start the server
server_ethernet.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
Each time it tells that it cannot find the hw… It does not recognize the shield…
My concern is that If have the following Hw configuration
From the code it seems that I can only set the CS pin… I need to set all the pins correctly or verify that they are using the right one
Any idea of what, how or where Can I verify this ?
Since the library is hardcoded for SPI.begin(), I suggest you fork the library / copy it in the lib/ folder of your project and modify the .begin() call to be as in this example.
Also, the SPI bus speed of 20MHz is hardcoded here. As far as I can see, it does not use the interrupt pin.
Ok max…
So changing the begin function and doing the init of the spi I should be able to configure the hw for my scenario.
In the example for the espressif framework is straighforward …
That’s the raw chip, but do you have that chip on a specific breakout board / carrier board that you baught from somewhere? Or did you just plug the DIP version into a breadboard and connected it to a clock and ethernet plug and all that?
I see. I have a ENC28J80 breakout board, I will connect it up to an ESP32 with the same pin mapping and see which library modifications are needed to get it working and report back.
void Ethernet_Init(void)
{
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(15); // Most Arduino shields
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// 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)
{
delay(500);
if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Ethernet cable is not connected.");
}
}
// start the server
server_ethernet.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
It is ok i don’t have the issues of hw not found and it is able to detect if the ethernet cable is connected from my laptop to the ethernet port…
But i would like to test the transmission between pc and the esp32 module…
How can I do that ?
void Ethernet_Task(void)
{
?????????
}
Moreover many settings are still obscure from the SPI setting… I need a test with a real communication in order to validate that
The problem is that although this creates and initializes a new hspi object, the entire rest of the file is still using the global SPI object which uses VSPI. The idea was that you modify SPI.begin() to include the right pins, not create a new SPI object that later goes unused. I’ll show you a more correct library fix for this in a moment (allowing you to pass a SPIClass* into the Ethernet class, for example.)