I am having an issue with my w5500 ethernet module. I have the correct library, I was able to lease my arduino's static IP and MAC address to my router, and was able to implement the WebServer example in the Arduino IDE. However my IP address changes everytime I upload a new sketch or unplug the arduino from my laptop and plug it again. To fix it, I need to reset the arduino and the ethernet module several times to have the correct IP address. The number of times I need to reset is very random.
I am hoping that someone had this issue before and was able to fix it. Attached is the screenshot of my serial to show the changing IP address and the correct one after resetting several times. (BTW, the correct IP address is 192.168.0.31).
/*--------------------------------------------------------------
Date: 10 January 2013
Author: W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192, 168, 0, 31}; // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
File webFile;
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.begin(9600); // for debugging
Serial.println(Ethernet.localIP());
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
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");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
I have the correct library pretty sure about it since I was able to implement the WebServer example in the IDE. It's just that everytime I unplug the USB cable to turn off my arduino or when I upload a new sketch then the IP address changes to very random values (as seen in the attached image above) unless I press reset button couple of times.
Note: I used the Ethernet library for 1.0.x for w5500 which I downloaded from wiznet.
How did you wire the module to the Arduino? Did you check that you don't have a slack joint in that wiring? What type of Arduino are you using? Do you have a link to the module you're using?
use the correct library! you should use the Ethernet2 library to make it work
check your SD card (pin 4 must set to high)
now this next tip is what really made mo go bonkers, here it is.
---- for this partiular module, and when you are using the arduino UNO r3, instead of using the SPI use the ICSP, in my case that fixed everything (problems such as random IP address, DHCP configuration, and all the errors that will make you want to throw it away)
So that's it. Thanks pylon for replying to my post. Hope this will help someone.