Skip to content

Instantly share code, notes, and snippets.

@baloghr
Forked from speters/uid.ino
Last active November 26, 2024 10:31
Show Gist options
  • Save baloghr/9bb75af7eba3e500c87a6f37982efd0f to your computer and use it in GitHub Desktop.
Save baloghr/9bb75af7eba3e500c87a6f37982efd0f to your computer and use it in GitHub Desktop.
Arduino atmega328p unique id/serial number

Purpose of this code is to read ID memory of the AVR processors with the aim to display its Lot ID and Wafer ID numbers. Usually, original chips have there reasonable numbers. Non-original chips contains FF here.

#include <avr/boot.h>
void print_val(char *msg, uint8_t val)
{
Serial.print(msg);
Serial.println(val, HEX);
}
void setup(void)
{
Serial.begin(9600);
while (!Serial) ;
#define SIGRD 5
#if defined(SIGRD) || defined(RSIG)
Serial.print("Signature : ");
for (uint8_t i = 0; i < 5; i += 2) {
Serial.print(" 0x");
Serial.print(boot_signature_byte_get(i), HEX);
}
Serial.println();
Serial.print("Serial Number : ");
for (uint8_t i = 14; i < 24; i += 1) {
Serial.print(" 0x");
Serial.print(boot_signature_byte_get(i), HEX);
}
Serial.println();
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment