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);
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.