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");
}
}
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.