Ethernet Arduino Giga r1 wifi

USR-ES1 module
I have it connected to:

D13 on CLK,
D12 on MISO,
D11 on MOSI,
D10 on ss.

But using GitHub - davenardella/Ethernet_SPI2: Arduino GIGA R1 Dual Ethernet project

just to test it with the ethernet.h library i keep getting the response:
Ethernet adapters were not found on both SPI interfaces. Sorry, can't run without hardware.

Would you perhaps know the solution?

/*
 Dual Web Server
  
 A quick and dirty example of using two Ethernet adapters contemporary on Arduino GIGA R1 WIFI 
 please refer to [..](https://github.com/davenardella/Ethernet_SPI2)
 for hardware examples

 2023 Dave Nardella

*/

/*
 Original credits
 -----------------------
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi
 
 */

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac_SPI1[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

IPAddress ip_SPI1(192, 168, 0, 177);

// Initialize the Ethernet servers

EthernetServer server_1(80);

void setup() {
  bool not_IF1;

// If you intend to use ETH0 on Ethernet shield and a Wiznet chip as ETH1 you could need 
// of an hardware reset pin.
// To do this connect the WXXXX reset pin on D8 (for example) and uncomment next lines
// DO NOT MODIFY THE ORDER OF THE FIRST TWO LINES
/*
  digitalWrite(8, LOW); 
  pinMode(8, OUTPUT);
  delay(650);
  pinMode(8, INPUT);
*/

  // 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
  }
  Serial.println("Double Ethernet WebServer Example");

  // start the Ethernet connection and the server on 1st SPI Interface
  Ethernet.init(10);   
  Ethernet.begin(mac_SPI1, ip_SPI1);

  // Check for Ethernet hardware present on 1st SPI
  not_IF1 = Ethernet.hardwareStatus() == EthernetNoHardware;

  if (not_IF1)
  {
    Serial.println("Ethernet adapters were not found on both SPI interfaces.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  else{
    if (not_IF1)
      Serial.println("Ethernet adapter was not found on 1st SPI");
  }

  // Check for link status
  if (Ethernet.linkStatus() == LinkOFF) 
    Serial.println("Ethernet cable is not connected on ETH0.");
 
  
  // start the 1st server
  server_1.begin();
  Serial.print("ETH0 server is at ");
  Serial.println(Ethernet.localIP());

}


void loop() {
  // ***********************************  
  // SERVER ON ETH0
  // ***********************************  
  
  // listen for incoming clients
  EthernetClient client_1 = server_1.available();
  if (client_1) 
  {
    Serial.println("new client on ETH0");
    // an HTTP request ends with a blank line
    bool currentLineIsBlank = true;
    while (client_1.connected()) 
    {
      if (client_1.available()) {
        char c = client_1.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard HTTP response header
          client_1.println("HTTP/1.1 200 OK");
          client_1.println("Content-Type: text/html");
          client_1.println("Connection: close");  // the connection will be closed after completion of the response
          client_1.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client_1.println();
          client_1.println("<!DOCTYPE HTML>");
          client_1.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client_1.print("ETH0 analog input ");
            client_1.print(analogChannel);
            client_1.print(" is ");
            client_1.print(sensorReading);
            client_1.println("<br />");
          }          
          client_1.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client_1.stop();
    Serial.println("client on ETH0 disconnected");
  }

}

image
image
image

I also tried the following code using the Ethernet2 library:

#include <SPI.h>
#include <Ethernet2.h>  // Use Ethernet2 for W5500

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  // Unique MAC address

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Ensure the serial port is open (for boards like Leonardo)
  while (!Serial) {
    ;
  }

  // Initialize SPI1 for the W5500
  SPI1.begin();

  // Manually specify the chip select (SS) pin
  Ethernet.init(10);  // Adjust pin according to your wiring (e.g., 10)

  // Add a small delay before initializing Ethernet to ensure the module is ready
  delay(1000);  // 1 second delay to allow W5500 to power up and stabilize

  // Start the Ethernet connection using DHCP
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Stop the program if DHCP fails
    while (true);
  }

  // Print the obtained IP address
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    if (thisByte < 3) {
      Serial.print(".");
    }
  }
  Serial.println();
}

void loop() {
  // Nothing in the loop for now
}

This gives a Failed to configure Ethernet using DHCP error.



The error Ethernet cable is not connected on ETH0. This could be caused by a faulty cable or a mismatch in Ethernet speed between your router and the module (some routers work only with gigabit speeds, while the USR-ES1 may work at 10/100 Mbps).

Yes i understand but initializing the ethernet is not working. So on ethernet.begin() tries to setup the connection but that dhcp and ip are both not working.

why not use SPI0 and the standard Ethernet library or the Mbed Ethernet library with my EMAC-W5500 driver?

Do you have example code? Using spi0?

spi0 is used in every example

I'm pretty new to this so sorry if i don't understand. But you're saying we can use SPI.begin(); with the D13 on CLK,D12 on MISO,D11 on MOSI, D10 on ss pins? i thought i needed SPI1.begin(); for the giga else it selects the wrong header?

don't use SPI.begin. the Ethernet library does it

default SPI is on the SPI header in the middle of the board, not on 11, 12, 13

EDIT: it is labeled as SPI1 in the datasheet, not as SPI0

Okay but i want to use pins 11, 12 and 13 and ss as 10. So that we i'm forced to use spi5 right?

Also i checked your W5500Emac library.

#include <W5500EMAC.h>
#include <PortentaEthernet.h>

Can PortentaEthernet be changed with just Ethernet because i use the giga?

Giga is a disguised Portenta (same MCU). and the PortnetEthernet library doesn't have anything special for that MCU. it is an Arduino wrapper over Mbed Ethernet API.

why do you want to use 11, 12, 13? even the Mega doesn't have SPI there

1 Like

Because of a pcb i connect that will block the middle pins. So it's possible using the PortnetaEthernet library and SPI5?

I will try later today.

Thanks for the help so far btw

in W5500-EMAC you can change SPI to SPI1 in W5500EMAC.cpp in
W5500EMAC& W5500EMAC::get_instance(

W5500EMAC& W5500EMAC::get_instance(void) {
  static W5500EMAC emac(SPI1);
  return emac;
}

SPI1 is on 11, 12,13

and using ethernet.h for arduino giga is possible with this and needed?

Yep, it worked with pins:
#define PIN_SPI_MISO (89u)
#define PIN_SPI_MOSI (90u)
#define PIN_SPI_SCK (91u)
#define PIN_SPI_SS (10u)

but when trying pins:
#define PIN_SPI_MISO1 (12u)
#define PIN_SPI_MOSI1 (11u)
#define PIN_SPI_SCK1 (13u)
#define PIN_SPI_SS1 (10u)

It does't work anymore because the SPI is then on SPI1 and the ethernet doesn't lib allow to pass a spi object.

see post 18

Yes i changed W5500EMAC:

W5500EMAC& W5500EMAC::get_instance(void) {
  static W5500EMAC emac(SPI1);
  return emac;
}

Also installed the library from zip downloaded from GitHub. For Giga it is neccessary to copy the Mbed Core Ethernet library to platform's libraries( i saw on a post of yours). Copy it from Portenta platform installation.

that doesnt work, here is the code:

/*
  Web Server

 A simple web server that shows the value of the analog input pins.

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi

 */

#include <W5500EMAC.h>
#include <PortentaEthernet.h>

// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {

  // 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
  }
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac);

  // 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.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 4; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          client.flush();
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

WARNING: library W5500-EMAC claims to run on mbed architecture(s) and may be incompatible with your current board which runs on mbed_giga architecture(s).
WARNING: library Ethernet claims to run on mbed, mbed_portenta, mbed_opta architecture(s) and may be incompatible with your current board which runs on mbed_giga architecture(s).
In file included from c:\Users\markv\Desktop\screen\libraries\Ethernet\src/Ethernet.h:125:0,
from c:\Users\markv\Desktop\screen\libraries\Ethernet\src/PortentaEthernet.h:3,
from C:\Users\markv\AppData\Local\Temp.arduinoIDE-unsaved2024922-2276-1549wrv.mwyc\WebServer\WebServer.ino:16:
c:\Users\markv\Desktop\screen\libraries\Ethernet\src/EthernetServer.h: In constructor 'arduino::EthernetServer::EthernetServer()':
c:\Users\markv\Desktop\screen\libraries\Ethernet\src/EthernetServer.h:34:20: error: no matching function for call to 'arduino::MbedServer::MbedServer()'
EthernetServer() {}
^
In file included from c:\Users\markv\Desktop\screen\libraries\Ethernet\src/EthernetServer.h:21:0,
from c:\Users\markv\Desktop\screen\libraries\Ethernet\src/Ethernet.h:125,
from c:\Users\markv\Desktop\screen\libraries\Ethernet\src/PortentaEthernet.h:3,
from C:\Users\markv\AppData\Local\Temp.arduinoIDE-unsaved2024922-2276-1549wrv.mwyc\WebServer\WebServer.ino:16:
C:\Users\markv\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.5\libraries\SocketWrapper\src/MbedServer.h:41:3: note: candidate: arduino::MbedServer::MbedServer(uint16_t)
MbedServer(uint16_t port)
^~~~~~~~~~
C:\Users\markv\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.5\libraries\SocketWrapper\src/MbedServer.h:41:3: note: candidate expects 1 argument, 0 provided
C:\Users\markv\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.5\libraries\SocketWrapper\src/MbedServer.h:33:7: note: candidate: constexpr arduino::MbedServer::MbedServer(const arduino::MbedServer&)
class MbedServer : public arduino::Server {
^~~~~~~~~~
C:\Users\markv\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.5\libraries\SocketWrapper\src/MbedServer.h:33:7: note: candidate expects 1 argument, 0 provided

exit status 1

Compilation error: exit status 1

you have to copy the Mbed Core Ethernet library next to SocketWrapper library * and it looks like the version doesn't match your Giga Mbed core version. install the Portenta Core and copy it from there. the version on GitHub has changes

  • here
    \Users\markv\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.5\libraries\
1 Like

Do you perhaps know a solution to use https and wss using ethernet on the giga?

EthernetSSLClient