Microcontroller unique id - EEPROM put/get help

Hi. Is there anything like a unique Id for every controller? Something like Mac adresses?

I want my every pcb to run same code but have something unique every different pcb.

If not, I want by flashing the same code, every chip to be unique.

Can I somehow when chip boots for first time to generate itself a random txt+numbers and store it somewhere internally and every time it restarts to read that value? If no value then generate new when booting etc.

Where Could I Store that and how?

Thanks

They newer chips (samd and mega0) have a unique serial number that you can read.

Older chips have eeprom where you could store something you'd created.

Hi,in IDE do Tools>Get Board Info

I don't know how you would access that in Arduino onboard code...

????

Hi everyone. Im trying to write and read in eeprom of my attiny85 but it doesnt seem to work well. If i try those "big" numbers it doesnt work properly.it returns other numbers(-31073,23352). If i try though to write smaller numbers like 11500, 11200 it works well. what am i doing wrong?

Im trying to write to eeprom with this code:
int address1=1;
int address2=200;
int mynumber1=99999;
int mynumber2=88888;
EEPROM.put(address1, mynumber1);
delay(2000);
EEPROM.put(address2, mynumber2);

and read with this code:
int address1=1;
int address2=200;
int mynumber1=0;
int mynumber2=0;
EEPROM.get(address1, mynumber1);
delay(2000);
EEPROM.get(address2, mynumber2);

An int is a 16-bit signed integer.

It can store a value between -32768 and 32767.

99999 and 88888 are outside of this range - they will be truncated to the low 16 bits, which will be 0x869F and 0x5B38 respectively - which as a signed 16-bit integer are -31073 and 23352, respectively. That happens the moment you assign them to int variables - you'd see the same numbers if you printed them out in the first sketch too!

DrAzzy:
An int is a 16-bit signed integer.

It can store a value between -32768 and 32767.

99999 and 88888 are outside of this range - they will be truncated to the low 16 bits, which will be 0x869F and 0x5B38 respectively - which as a signed 16-bit integer are -31073 and 23352, respectively. That happens the moment you assign them to int variables - you'd see the same numbers if you printed them out in the first sketch too!

ya makes sense.i found out few mins ago and got it to work with char instead of int. thanks!

The new tinyAVR 0-series and 1-series parts (supported by my megaTinyCore) also have the serial number.

The t85 is yesterday's news. The new ATtiny412 (in 8-pin package, only 4k of flash) and ATtiny1614 (in 14-pin package, 16k flash 2k sram) are much sexier parts unless you're using Timer1 clocked off the PLL for 64MHz timer clock and ultra-high-speed PWM. Among other things, they have unique serial numbers in them, generally better peripherals, and are cheaper.

There are also slightly cheaper 0-series (replace 1 in part number with a 0) which lose the DAC (yes, the 1-series parts all have an on-chip DAC!) and type D timer*, and the flash caps out at 16k (the 20 and 24-pin parts, ending in 6 and 7 respectively, have a 32k version available, with 2k SRAM), and the 16k 0-series parts have 1k of SRAM instead of 2k). Also worth keeping in mind if you do decide to step up to these parts, the 16/32k 1-series parts also have a second type B timer and a second ADC - the 1614 is a spectacular part considering the small package; the header files suggest that a 3214 was planned at one point, though sadly it doesn't seem to exist.

  • The type D timer, in practical terms, gets you 2 extra PWM channels on the 20 and 24 pin parts, and lets you move millis() timekeeping onto the type D timer (which is hell to reconfigure anyway) so you can take over the easy-to-use type A and B timers without breaking millis timekeeping