1

I'm trying to figure out, what and how can get as unique identification number or any other kind of ID equivalent from particular Arduino Uno micro-controller from C# desktop application with serial port data

In case of Uno, I have COM3 open:

myport.PortName = comPort;
myport.BaudRate = 9600;
myport.Open();

But I'm not sure, how to read such data as ID of chip, for example with EEPROM Get :

#include <EEPROM.h>
void setup() {
  float f = 0.00f; 
  int eeAddress = 0; 
  Serial.begin(9600);
  while (!Serial) { 
  }
  Serial.print("Read float from EEPROM: ");
  EEPROM.get(eeAddress, f);
  Serial.println(f, 3);    
  secondTest(); //Run the next test.
}
struct MyObject {
  float field1;
  byte field2;
  char name[10];
};
void secondTest() {
  int eeAddress = sizeof(float); 
  MyObject customVar; 
  EEPROM.get(eeAddress, customVar);
  Serial.println("Read custom object from EEPROM: ");
  Serial.println(customVar.field1);
  Serial.println(customVar.field2);
  Serial.println(customVar.name);
}
void loop() {}

and C#:

private void button1_Click(object sender, EventArgs e)
{
    textBox1.Text = myport.ReadExisting();
}

I get some completely misunderstood result:

Read float from EEPROM: ovf
Read custom object from EEPROM: 
ovf
95
_^^]]]\\\\fedc

What must be the output variable to get unique id from particular micro-controller:

  Serial.println(customVar.field2);
  Serial.println(customVar.name);
dbc
  • 104,963
  • 20
  • 228
  • 340
  • @vasily.sib Hello, yes question edited –  Dec 29 '18 at 04:21
  • your code sample is a mess. At first you read first 4 bytes of your eeprom and assume, that they are a float value, but as your `Serial.println(f, 3)` returns `ovf` (which is a short name for "overflow" I think) I can tell that they are not. Next, you read 15 bytes starting from 4 of your eeprom and assume that this is your structure. Again, `ovf` instead of float value, then value 95 and then 10 random characters. How this may help you to get board ID? It is just a random code, that do nothing? – vasily.sib Dec 29 '18 at 04:32
  • your [link](https://www.arduino.cc/en/Tutorial/EEPROMGet) exactly telling, that `ovf` means that `data inside the EEPROM is not a valid float` – vasily.sib Dec 29 '18 at 04:34
  • @vasily.sib Well It is not random, I found this method on Arduino site, and I have tried to get result, so I'm trying to figure out how to do it proper way, that's why I have post this question. So, what is your advice, or you're asking me how to do that? –  Dec 29 '18 at 04:55
  • https://arduino.stackexchange.com/questions/279/how-can-i-get-a-unique-id-for-all-my-arduino-boards – gre_gor Dec 29 '18 at 05:09
  • What I mean is that your question looks like "[Here](https://en.wikipedia.org/wiki/First_law_of_thermodynamics) is first law of thermodynamics. How can I launch a rocket to the space?" We need a lot more info: 1. What kind of _"unique identification number"_ are we talking about? 2. Is there any datasheet which tell you about this number? 3. Why do you think it is in eeprom? – vasily.sib Dec 29 '18 at 05:12
  • @vasily.sib Well, I'm not sure about comparisons of first law of thermodynamics and rocket in terms of distance from my attempt and correct method for the desired result, but what about "unique identification number" I guess it is absolutely clear in my question. To identify unique board, for example for database record with any available value able to be used as a unique number. I don' know anything about such datasheet or possibility to get it from eeprom, it is only found answer close to this topic. I've also noticed that I do not know exactly what data I am able to get –  Dec 29 '18 at 05:30
  • Exaclty. As there is no direct relation between `first law of thermodynamics` and a `rocket` - there is no relation between your question title and your code sample. You first question should be "Is there any unique identification number exist for arduino uno board out of the box?" and as far as I can tell - there is no. – vasily.sib Dec 29 '18 at 05:38
  • @vasily.sib So, you're saying there is no id number and it is impossible. Then would be a proper include ID to the uploaded sketch different for each separate board, or is there some more correct method? –  Dec 29 '18 at 05:46
  • The correct method is find board and chip datasheets and look for some chip unique id or serial number getting method. If there is no - invent your own (for example - store this number somewhere in flash or eeprom at compile time). – vasily.sib Dec 29 '18 at 05:50

1 Answers1

1

Atmega328P used in official Arduino UNO does not have any factory-programmed unique ID. However, Atmega328PB does have 10 bytes long preprogrammed serial number.

Atmega328PB seems to be quite compatible with Atmega328P. Differences are described in this application note: http://ww1.microchip.com/downloads/en/AppNotes/Atmel-42559-Differences-between-ATmega328P-and-ATmega328PB_ApplicationNote_AT15007.pdf

You can read serial number with boot_signature_byte_get() function from avr/boot.h: https://www.nongnu.org/avr-libc/user-manual/group__avr__boot.html#gaf375d2543ba38dc56697b4f4bc37a717

There are boards available with Atmega328PB chip, just google for "Atmega328PB arduino".

In case you cannot change the chip, then you would need to generate and program unique ID into your chip yourself.

user930473
  • 156
  • 1
  • 5