Adding Serial Number from PC

Hi All,

I am trying to assign my Arduino a ID number during compile time. Specifically I would like to have the last programmed Serial ID stored on my PC. Every time I program a new board I would like the Arduino to take on the latest ID and the PC then needs to increment to the next ID. So if I have 5 boards that I program in a row. they would have incrementing IDs from 1-5. Anyone know how to go about this?

Thanks, PeaTear

You can put the time and date in the Arduino with TIME and DATE. That is the time and date of the computer when the compiler was compiling.

The DS18B20 has a unique ID number. If I remember it correctly, the ATmega32U4 in the Arduino Leonardo and (Pro) Micro have an unique ID number well. [Update] The ATmega32U4 does have a lot of ID bytes, but not a guaranteed unique ID.

To get a ID from 1..5 in the Arduino is not easy. You could write a script for the Arduino environment on the PC.

The most common way is to store a ID of that board in EEPROM.

What is it for ?

Hi, It's easy to get the internal serial number with Tools>Board Info. It's like:

BN: Arduino/Genuino Uno
VID: 2341
PID: 0043
SN: 7563830323735141C1B2

Does anyone have code to retrieve that within an arduino sketch?

With boot_signature_byte_get(): https://forum.arduino.cc/index.php?topic=392433.msg2708936#msg2708936

The number returned by the Arduino IDE is from the usb-serial ATmega16U2 chip ! That will be different than the number retrieved from a sketch which is from the ATmega328P in the Arduino Uno. I don't know how the Arduino IDE creates that ID from the signature bytes. And not every microcontroller has a guaranteed unique ID. The signature bytes are mainly information about the chip die and its position on the wafer.

PeaTearDial: Hi All,

I am trying to assign my Arduino a ID number during compile time. Specifically I would like to have the last programmed Serial ID stored on my PC. Every time I program a new board I would like the Arduino to take on the latest ID and the PC then needs to increment to the next ID. So if I have 5 boards that I program in a row. they would have incrementing IDs from 1-5. Anyone know how to go about this?

Thanks, PeaTear

To do exactly what you describe you would need a program running on the PC that provided the next ID number to the Arduino. Once the Arduino acknowledged receipt and storage of the ID number, probably in EEPROM, the PC application would then need to increment the ID number and possibly save it to disk ready for the next board to be programmed.

Ideally you would do this using a custom PC program, but it should also be possible to do it using a terminal emulator program that supports the writing of scripts.

I'm using the ATMEGA328P... which as far as I know doesnt have an internal unique ID. Currently I set the ID manually and save to the EEPROM.

Koepel: What is it for ?

its to identify an individual device on a wireless network.

UKHeliBob: To do exactly what you describe you would need a program running on the PC that provided the next ID number to the Arduino. Once the Arduino acknowledged receipt and storage of the ID number, probably in EEPROM, the PC application would then need to increment the ID number and possibly save it to disk ready for the next board to be programmed.

I guess this would have to be done after programming using a bash script or something similar?

I guess this would have to be done after programming using a bash script or something similar?

You could do it as part of the program.

When setup() runs, if the ID had not already been set (see below), it could request an ID from the PC, save it, send back an acknowledgement to the PC and set a flag in EEPROM to indicate that a valid ID was present. The flag would prevent the program requesting an ID on subsequent runs.

UKHeliBob: it could request an ID from the PC, save it, send back an acknowledgement to the PC and set a flag in EEPROM to indicate that a valid ID was present.

That sounds perfect... but how would it work. like how would the atmega request this from the PC? I guess just through a Serial connection?

PeaTearDial: That sounds perfect... but how would it work. like how would the atmega request this from the PC?

The easiest way would be by sending a message over Serial that the PC would receive and act on. There is a complication in that the code will have been uploaded to the Arduino via Serial and that the Serial interface will be in use by the IDE. You could use SoftSerial so that there is no clash between the IDE and t5he ID program

An alternative would be to program a batch of boards using the IDE then use a separate program on the PC to send the IDs to the Arduinos. How many boards do you envisage allocating IDs to ? If only a few then you could write a small Arduino program to receive the ID and save it and enter the ID manually in the IDE or a terminal emulator. Then you could upload the main program.

PeaTearDial: I'm using the ATMEGA328P... which as far as I know doesnt have an internal unique ID. Currently I set the ID manually and save to the EEPROM.

its to identify an individual device on a wireless network.

Is it WiFi? If so, just use the MAC address of the wifi chip?