Questions on setting up the arduino Ethernet shield

Hi guys not sure if this is the place for my question but ill just ask and move it later on if its wrong.

So i have a question, how do i find the mac address and ip address for the Arduino Ethernet Shield?

Ive looked around the internet about both the mac address and ip address for the arduino ethernet shield and this is what i have come up with.

Firstly, for the mac address what ive understand is that its dependent on the Ethernet shield, if its the newer one i need to refer to a sticker, if not i can randomly assign one to the ethernet shield. For mine(it says Ethernet R3 on the back) i think i can assign a random one. So can i just use a website that can generate a random unique mac address? Say something like this website > Link: MAC Address Generator
And then go byte mac[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; with AA being the every 2 digit of the mac address generated from that website.

And then secondly, about the Arduino Board IP address what ive understood so far is i can use the DHCP Address Printer sketch in the examples tab of the Arduino IDE. I did an attempt using that sketch but it didnt work as nothing appeared on the serial monitor where the IP adress should have appeared. I think its because of this as shown below as Im not sure how to Initialize it properly.

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

Many thanks in advance! :smiley:

Which ethernet shield do you have? Is it w5100 based? Some are w5200 or w5500 ICs.

Do you have it connected to a router?

You should be able to use the default MAC in the DHCP address printer example. DEAD BEEF FEED.

Sorry for the slow reply and thanks for the MAC address part.

To answer Do you have it connected to a router?
Ans: I have it connected directly to the wall wire jack. Is that a bad thing?

And to answer Which ethernet shield do you have?
Ans: I think its a w5100 based, cant really tell the chip is really faded away it looks like the picture in this link: http://wiznetmuseum.com/wp/wp-content/uploads/2014/11/Randy-Sarafan.jpg

Prinny:
Ans: I think its a w5100 based, cant really tell the chip is really faded away it looks like the picture in this link: http://wiznetmuseum.com/wp/wp-content/uploads/2014/11/Randy-Sarafan.jpg

MAC address: Use a MAC address as you like, but it must be unique in your network! You define it in the sketch code (the W5100 chip has no built-in MAC-Address)! Never use the same MAC address twice within the same LAN network at the same time (or you will have to restart all servers/clients and network devices in your LAN to make it work again!

IP address: Use DHCP to retrieve an IP address from the DHCP server (i.e. router) in your network or ask the network administrator of the network you are talking about to give you a fixed IP address if you like that better!

jurs:
IP address: Use DHCP to retrieve an IP address from the DHCP server (i.e. router) in your network or ask the network administrator of the network you are talking about to give you a fixed IP address if you like that better!

Erm thats my problem im using the DCHP printer sketch found in the arduino example thing to find the ip address of my ethernet shield and it doesnt work... im not exactly sure if im doing the right thing but the whole code is like this

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (; ; )
;
}
// print your local IP address:
printIPAddress();
}

void loop() {

switch (Ethernet.maintain())
{
case 1:
//renewed fail
Serial.println("Error: renewed fail");
break;

case 2:
//renewed success
Serial.println("Renewed success");

//print your local IP address:
printIPAddress();
break;

case 3:
//rebind fail
Serial.println("Error: rebind fail");
break;

case 4:
//rebind success
Serial.println("Rebind success");

//print your local IP address:
printIPAddress();
break;

default:
//nothing happened
break;

}
}

void printIPAddress()
{
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}

Serial.println();
}

i understand most of it but the thing is this part below do i need to do anything else to it or just leave it and wait for my arduino to respond?

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

Erm also im using my school network for this dont think they will let me have a ip address for this... I could always asks but id prefer if i could get the above code working.

To answer Do you have it connected to a router?
Ans: I have it connected directly to the wall wire jack. Is that a bad thing?

I mean the CAT5 cable from the ethernet shield. Is it connected to a router? If the wall wire jack is a CAT5 socket, is it connected somewhere to a router?

Prinny:
Erm thats my problem im using the DCHP printer sketch found in the arduino example thing to find the ip address of my ethernet shield and it doesnt work...

A solution seems to be simple.

Just replace the non-working code with another code that does work.

What about that?

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

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.print("Starting network ...");
  byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
  if (Ethernet.begin(mac))
  {
    Serial.println("OK");
    Serial.print("local IP address: ");
    Serial.println(Ethernet.localIP());
  }
  else Serial.println("FAIL -Failed to configure Ethernet using DHCP");
  
}

void loop() {

}

Jurs does have a good idea. Let's try some other stuff. If jurs' new code doesn't work, try this. It tests the SPI bus and the SPI side of the w5100. Don't change anything in this code. Does this show 192.168.0.2 on the serial monitor? If so, the SPI stuff is working. If not, you have a hardware problem.

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

edit: If you have a SD card in the shield's slot and you haven't been disabling it, that will cause the DHCP function to fail.

Okay thanks ill give your solutions a try later ill keep you all posted.

And about the router thing no, im just directly connecting the cat5 cable from the wall jack directly into the ethernet shield cat5 port. Im i not surpose to do that?

Prinny:
And about the router thing no, im just directly connecting the cat5 cable from the wall jack directly into the ethernet shield cat5 port. Im i not surpose to do that?

What is on the other end of that wall jack?

Does the serial monitor show the DHCP failed after a couple minutes or does it lock up?

SurferTim:
What is on the other end of that wall jack?

That i really dont know, i think maybe directly connected to my school's server?

Also the serial monitor doesnt show anything, even after i leave it there for a few minuets... If your asking about the DCHPAddressPrinter Sketch.

For your solutions i havent tested it out yet, currently dont have the Arduino board with me. Ill only be able to test it out tmr.

That is not a good sign. You might want to ask the network administrator about the DHCP. It may be trying to issue a IPV6 address.

Have you tried the code with the shield attached to a residential router like a Linksys or D-Link?

UPDATE + EDIT: I just tested out both the codes you guys provided and it both worked! So i went to try out the IP i got on my sketches but it didnt work. So I went back to check, and now both the solutions don't work...

For jurs code the serial monitor previously did show an IP address but now when i load it up, it shows just shows the

Serial.print("Starting network ...");

on the serial monitor and nothing else.

And about your solution SurferTim, it did also show an IP address the one that is inside the code and one(different one) even when I removed the IP address in code. But now when i use your code without changing anything it just shows an IP of 0.0.0.0 does this mean the board im using has some kind of hardware problem? EDIT: Erm... it seems to show the ip u specify in the code only when i didnt connect cat5 cable to the ethernet shield

And also about that router thing, dont exactly have one that is working right now.

One more thing the arduino sketchs i looked at refrence for my own all mention this line

byte ip[] = {123,456,7,890}; // Your Arduino device IP address

Does the DCHP actually give me what im looking for which is to put in the above line? Many apologies if what ive been asking is the wrong thing.

For my home setup, I made the first byte '0xDE', and then used a d20 to determine the rest of the bytes. If course, you have to re-roll any numbers over 16. Using a d12 and values 1..C would perhaps be a good compromise.

If your IP is showing 0.0.0.0 on my test sketch, you have a SPI bus problem. Insure the ethernet shield is firmly seated on the Arduino. Check the ICSP pins (2x3 socket under the shield) carefully to insure you don't have a bad solder joint on those.

If you have a SD card in the shield's slot, remove it for now. We can work on that once the w5100 is working ok.

PaulMurrayCbr:
For my home setup, I made the first byte '0xDE', and then used a d20 to determine the rest of the bytes. If course, you have to re-roll any numbers over 16. Using a d12 and values 1..C would perhaps be a good compromise.

Erm PaulMurrayCbr, im not too sure what you mean by this. Totally bad at this ethernet stuff.

And also SurferTim i finally got it to work! Looks like i didnt place the ethernet shield properly i think. Another possible reason i think is that both RX and TX LEDS were both blinking when i tried your test sketch and the IP was showing 0.0.0.0, compared to now when only the RX LED is blinking and both your sketch and jurs sketch are working. If you have a solution for what i just describe it will be very much appreciated!

Other then that once again Thanks to Jurs and you for your help!

Prinny:
And also SurferTim i finally got it to work! Looks like i didnt place the ethernet shield properly i think.

That is the most common reason. If those ICSP pins are not seated fully, the SPI bus will malfunction.