Skip to content

Instantly share code, notes, and snippets.

@mgk
Created January 29, 2016 15:25
Show Gist options
  • Save mgk/c9ec87436d2d679e5d08 to your computer and use it in GitHub Desktop.
Save mgk/c9ec87436d2d679e5d08 to your computer and use it in GitHub Desktop.
Arduino SAMD / Arduino Zero / Arduino M0 chip unique serial number
/**
* Print SAMD chip serial number.
*
* http://atmel.force.com/support/articles/en_US/FAQ/Reading-unique-serial-number-on-SAM-D20-SAM-D21-SAM-R21-devices
*/
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
printChipId();
delay(3000);
}
void printChipId() {
volatile uint32_t val1, val2, val3, val4;
volatile uint32_t *ptr1 = (volatile uint32_t *)0x0080A00C;
val1 = *ptr1;
volatile uint32_t *ptr = (volatile uint32_t *)0x0080A040;
val2 = *ptr;
ptr++;
val3 = *ptr;
ptr++;
val4 = *ptr;
Serial.print("chip id: 0x");
char buf[33];
sprintf(buf, "%8x%8x%8x%8x", val1, val2, val3, val4);
Serial.println(buf);
}
@SWoto
Copy link

SWoto commented Jul 2, 2020

Thank you, it worked for me.

@eyetach
Copy link

eyetach commented Jan 18, 2021

Hey thanks! Worked for me on Adafruit FeatherM0's. Before this I had been using extra analog pins to hardwire unique ID's for feathers with RFM69 packet radios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment