Mega + Ethernet Shield - Random IP Problem

I'm using an Arduino Mega and an Ethernet Shield in my project. However, usually the board is not assigning my desired IP address; instead, it assigns a random one.
The IP address I assigned does not conflict with any other IP addresses on the network.
I replaced the Ethernet Shield with another one, but the problem still persists.

e.g the code below gets
3.48.192.6

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
IPAddress ip(192, 168, 1, 77);
IPAddress dns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

EthernetServer server(80);

It won't get anything, it won't even compile or upload to the Arduino.

Please read the forum guide in the sticky post. You have had 3 years since your last post to get around to reading it.

I noticed that when I completely disconnect and then reconnect the power, I get the desired IP address. However, when I press the reset button, it doesn't work. Could it be a hardware issue?

Hi, @ta2bss

When you do a power up reset, you reset the Mega and the Ethernet Shield.

When you do a button reset, you ONLY reset the Mega.

Tom.... :smiley: :+1: :coffee: :australia:

That's some lousy pupil.

I don't know much about these shields, can't they be reset from the sketch? Seems stupid that they need a hard reset to have old settings cleared. I say they but it's probably different for different shields as well.

If you skip the selfassigning part and use DHCP, what IP address does that yield after a reset of the Mega?

What shield do you got there btw?

It fails to configure Ethernet using DHCP
But when disconnect and reconnect it gets an IP from my networks IP Range.
It's a shield with SD Card slot , I think it's Wiznet W5100.
I will try to reset it from the sketch later.

You have to explain those two lines. First one tells us it can't get IP from network (DHCP), second that it gets an IP from network after disconnect and reconnect (of what?)