Unique MAC addresses? Best practice?

My first arduino project is nearing completion (first stage at least). I have a display box with a number of 7-segment 4-digit displays. The Arduino Uno R3 has an official Arduino Ethernet shield. Values for display are sent through UDP and it is all working nicely.

I am now looking that several of these may be on the same network attached to different instruments. I have built in commands to allow me to switch each unit to use DHCP or static IP addressing and to supply static IP addresses in case I want to set up each box and leave the same sketch (these values get saved in EEPROM and read in during setup along with various other configuration parameters).

The only thing I am wondering about is the MAC addressing. All the examples I have seen have a hard-coded MAC address in the sketch. At the moment this is what I have too. However this means if I put the same sketch in 2 boxes without modification they will have the same MAC address (so I could have 2 boxes with unique IP address from DHCP, but with the same MAC address). Given that these are supposed to be unique I feel this can't be a good thing, particularly on the same network segment.

While I could hand modify the sketch and burn it individually in to each box this seems a bit "Heath-Robinson". I could also extend my code to allow the MAC address to be changed later (stored in EEPROM) and read at start up (as I have done with other configuration settings), but I thought this sort of issue can't be that unusual and wondered how others had dealt with it. I have tried searching but got rather a lot of hits with the search term "mac" and have not found a better one.

Thanks.

[I have not posted any code here because this is rather a generic question, and my sketch is quite long. The way Ethernet is set up comes directly from the Playground examples. If the sketch is needed I can happily post it later]

Once this is finished I will try and post some pictures and the sketch in case it is of interest to others.

Just thinking out of the box..

Write a routine to generate a random mac address and store it in eeprom first time run...(if it's not already been generated)

Certainly one idea. Thanks I will consider that alongside being able to set it externally with a command (I am likely to have a test harness running on a PC to check each box and configure, so setting the MAC address may be feasible here as there will only ever be one box). I am looking for the smallest set of code on the Arduino to keep inside memory constraints.

Any others that people are already using?

FlyingWhale:
While I could hand modify the sketch and burn it individually in to each box this seems a bit "Heath-Robinson".

It isn't. For this reason:

I am looking for the smallest set of code on the Arduino

If you are making thousands of boxes for one destination, you probably need a way to programme the programme, if only to ensure against duplication. Otherwise the above should suffice.

Thanks for the thoughts and comments, Nick.

Fortunately I am only ever likely to be doing 2 of these, however they are in the same lab.

The question was really one of curiosity to see if there was a generally accepted best practice that I had just not found. For me, the Arduino is a new playground and I like to try and stick with tried and tested approaches from those more experienced than me. I am also coming to realize that Arduino is a great place to just try stuff out. So sometimes going with your own ideas is the way to go. I think for now I am going to go with the approach of being able to send a new MAC address to a unit and have a small configuration and test application on a PC. In fact I already have that for everything else. However I might also set up the random MAC on first check just out of interest.

Thanks for both sets of suggestions from those who have replied.

Having more fun now building a decent object in Delphi on the PC to encapsulate the functionality and to also deal with finding and selecting the appropriate unit for the major instrument control application. (Life doesn't get much better than this playing with 3 million volt accelerators, 5 axis motor controlled stages and analysing novel new materials).

Which version of delphi? Quickest way would be to generate a TstringList and save the list, turn on the no duplicates property then spit out the mac address to each new unit (generate a random one to begim with to make sure there's no conflict) and store it on eeprom.

Do you plan on using a SD card? That is where I store my network setup. I use a file named network.txt and start the SD card first, retrieve that file data, and start the w5100 with it.

Just a thought...

I've approached this in a couple ways.

(1) If I'm using a static IP address, say W.X.Y.Z, then I'll use 2:0:W:X:Y:Z for the MAC address. The second-least-significant bit of the first octet identifies the MAC address as locally administered.

(2) Include a chip in the project that has a unique ID. My favorite is Microchip's MCP79411 RTC since I often use an RTC anyway. An even less expensive and smaller (SOT-23 package) alternative is the 24AA02E48 EEPROM with EUI-48 ID, which goes for about a quarter in single quantities.

Similar devices are available from other manufacturers but those are the ones I'm most familiar with.

Do you plan on using a SD card? That is where I store my network setup. I use a file named network.txt and start the SD card first, retrieve that file data, and start the w5100 with it.

Thanks. I had thought about that. The Ethernet shield does have the SD Card slot and I had wondered about doing this. It is certainly a possibility, though I have not checked whether there would be any pin clashes with what I am already doing. I will think about it.

(1) If I'm using a static IP address, say W.X.Y.Z, then I'll use 2:0:W:X:Y:Z for the MAC address. The second-least-significant bit of the first octet identifies the MAC address as locally administered.

(2) Include a chip in the project that has a unique ID. My favorite is Microchip's MCP79411 RTC since I often use an RTC anyway. An even less expensive and smaller (SOT-23 package) alternative is the 24AA02E48 EEPROM with EUI-48 ID, which goes for about a quarter in single quantities.

Given that the hardware is now pretty much done, and I will only be building 2 I think the extra hardware approach will not work for this project. If I do get more involved with Arduino stuff and end up building an high volume products it is a good idea, and the links will give me a place to look in the future, thanks. The first suggestion however does sound interesting, though of course if I go with DHCP it will not necessarily work.

Which version of delphi? Quickest way would be to generate a TstringList and save the list, turn on the no duplicates property then spit out the mac address to each new unit (generate a random one to begim with to make sure there's no conflict) and store it on eeprom.

Another idea thanks. I have used most versions of Delphi all the way from 0.9 when I picked up a free pre-release copy at the launch of Delphi at Comdex San Francisco in 1995. Currently my various projects are split between Delphi 7 (where I am still having problems replacing 3rd party stuff for newer versions, and getting round to dealing with Unicode issues), and XE3. However I also have XE5 for exploration of porting some apps to mobile.

Thanks to all. I have enough ideas to get me moving, but any other ideas are always welcome.

Adding the SD card uses only D4 as the SD slave select. If you can avoid using D4 for anything else, you are in!