How to read the ID (serial number) of an Arduino?

Hi all,

Is there a way to retrieve the ID ( serial number on the sticker on the back of the Arduino, e.g. "CD1234") of an Arduino via code?

I remember Phidgets offered that feature and i need it for my current feature. Suggestion for any means of identification of an individual Arduino are welcome. It should however best be independent of the code loaded on the Arduino and the data stored on the EEPROM.

Cheers

The FTDI chip (USB/serial interface) on the Arduino board has a unique serial number. You can query this number through the USB driver on the host (PC) side.

Thanks a lot, but i wonder, can the Arduino send this ID via serial?

No. The Arduino can't read from the FTDI chip.

What difference does it make if it's a pull operation from the PC or a push operation from the Arduino? In other words, what are you trying to accomplish?

I am making a flexible network of arduino-embedded interactive components.

The Arduino's should be able to communicate their ID to each other, so they can figure out how they are connected and what the overall geometry of the component assembly is.

From your replies i figure the only way to do this is to once write the Arduino serial number to the EEPROM and then read it back whenever needed. Unless... there are other ways to do it?

Another approach is to give each Arduino a unique address, either in the softwarre or by attaching a 4 (or 5/6/7/8) position dip switch to some digital pins.

so they can figure out how they are connected

That's OK

and what the overall geometry of the component assembly is.

That is very tricky. Have you though how this would happen. Each arduino will have it's own unique map because it is a unique position in the topology. It will also be impossible to do this with a simple broadcast message system, you will need at least a pair of input / output communication links per arduino.

Here's the code which works for me.
It is important to minimize how often the EEPROM is read from and written to, because it has a life estimate of only 100.000 read/write cycles.

// WRITES ARDUINO SERIAL TO EEPROM
//
// do this only once on an Arduino, 
// write the Serial of the Arduino in the 
// first 6 bytes of the EEPROM

#include <EEPROM.h>
char sID[7] = "CD6484";


void setup()
{
  Serial.begin(9600);
  for (int i=0; i<6; i++) {
    EEPROM.write(i,sID[i]);
  }
}

void loop() {
  Serial.println(sID);
}
// READS ARDUINO SERIAL FROM EEPROM
//
// reads the Serial of the Arduino from the 
// first 6 bytes of the EEPROM

#include <EEPROM.h>
char sID[7];


void setup()
{
  Serial.begin(9600);
  for (int i=0; i<6; i++) {
    sID[i] = EEPROM.read(i);
  }
}

void loop() {
  Serial.println(sID);
}

Another approach is to give each Arduino a unique address, either in the software or by attaching a 4 (or 5/6/7/8) position dip switch to some digital pins.

that sounds interesting! for my application it would be not ideal though, i'd never want to change the switches and i'd loose a few pins

It is important to minimize how often the EEPROM is read from and written to, because it has a life estimate of only 100.000 read/write cycles.

That's incorrect - you can read as often as you like, the limitation is on erase/write cycles.

That is very tricky. Have you though how this would happen. Each arduino will have it's own unique map because it is a unique position in the topology. It will also be impossible to do this with a simple broadcast message system, you will need at least a pair of input / output communication links per arduino.

We have Arduinos linked up via '4052' multiplexers.
Each Arduino listens to four other Arduinos in turn, and sends to 'their' multiplexers as well. Listening in works well, we still have to see whether it works bi-directionally.

I'll try to have the Arduino network broadcast information on individual connections over time (like 'i'm no. 1337 and i'm next to you!', 'i'm no. 42 and i'm connected to no. 1337!').This way, they could have at least a map of their immediate neighbourhood.

A custom-made modeler app will collect this information and adapt the representation of the assembly:

That's incorrect - you can read as often as you like, the limitation is on erase/write cycles.

indeed, i failed at RTFM ::slight_smile:

Thanks HCF, that was the exact code I was looking for.

How about using a DS2401 its has a unik ID and uses one wire.

You can also assign or code generated by the software ID eg 485fcba0-e61a-11df-9492-0800200c9a66, and left as a global variable. (This number may be repeated once every 100 years)
So no need to remove the FTDI or an EEPROM.

Or the second option is with the Dallas DS2401, separates a unique pin (Wire one), this number is unique.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260959358/11
http://www.famkruithof.net/uuid/uuidgen
http://pdfserv.maxim-ic.com/en/ds/DS2401.pdf

Code:
/ / WRITES TO SERIAL EEPROM Arduino
/ /
/ / Do this only eleven on an Arduino,
/ / Write the Serial of the Arduino in the
/ / First 6 bytes of the EEPROM

Include <EEPROM.h>

sID char [7] = "CD6484";

void setup ()
{
Serial.begin (9600);
for (int i = 0; i <6; i + +) {
EEPROM.write (i, sID );

  • }*
    }
    void loop () {
  • Serial.println (sID);*
    }
    Code:
    / / Arduino READS FROM SERIAL EEPROM
    / /
    / / Reads the Serial of the Arduino from the
    / / First 6 bytes of the EEPROM
    # Include <EEPROM.h>
    sID char [7]
    void setup ()
    {
  • Serial.begin (9600);*
  • for (int i = 0; i <6; i + +) {*
    _ sID = EEPROM.read (i)_
    * }*
    }
    void loop () {
    * Serial.println (sID);*
    }