Storing Unique IDs in EEPROM

I have a "fleet" of about 50 arduino minis and pro minis that run a synchronized light show. I want to assign a unique "unit_number" to each of them and have it stored in EEPROM.
I realize I could write sequential ID numbers to each unit's EPROM, but I'd prefer to do this without changing the sketch for each one. Also, doesn't the EEPROM get erased when a new sketch is uploaded?
Can I pass a command line parameter during programming?
Any ideas how to do this efficiently?

Nope. The flash memory does though. Have you looked at the EEPROM reference yet?

1 Like

Optiboot, the default bootloader for AVR Arduino, does not support writing to EEPROM.

How often will the unit numbers change?

Upload a program that accepts a serial input, reads it back for confirmation, then writes it if confirmed to the EEPROM. Then load the light show code and the EEPROM value is already stored. Not super efficient but doable.

i'm doing similar

the arduino code will include code to read commands from the serial monitor that set variables based on the commands. there is also a command the writes those variable values to EEPROM which the code will read at startup.

i'm using TLVs to format the multiple data in EEPROM. the length value makes it possible to skip TLVs when searching for a specific type.

Got one or two analog pins free on each Arduino? With a few resistors, you could give each Arduino an ID in hardware.

Clever idea! Will remember this in future. My current set is all assembled and installed already. I have access to reprogram them but would rather not crack each one open.

One time only. I want to "brand" each unit with an immutable number that can then be used internally to individualize each unit's behavior.
Knowing that the bootloader doesn't write to EEPROM helps. Thx.

I'm wondering if a compiler macro like COUNTER might be the ticket.

Thx. That's helpful.
I'm wondering if a compiler macro like COUNTER might assign an incremented value to a variable that then gets written into EEPROM in setup(). I'll try it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.