user50183: I'm using EEPROM to store project settings non-volatile.
After reuploading the sketch to my board (over SPI via ArduinoISP), the EEPROM is reset to full 0xFFs and I have to manually do a "software reset" with a second switch, which initializes the EEPROM with its default values.
Is it possible to run a segment of code once, and only once, after booting up the first time after being programmed?
I'm working around it by checking whether a piece of EEPROM is 1 at startup when it would always be 0 after the initialization and during usage, but surely there's a cleaner alternative than checking for an EEPROM bit each time.

user47164: I've actually done some tinkering with this sort of thing, or alternatively how to ensure previous EEPROM (or similar) settings are formatted on upload of a new sketch.
There are two values (C macros, in this case) that are baked into a program when it is compiled (for Arduino, the program is recompiled on each upload) that can be used to tell if the programming is "fresh."
The values you'd want are __DATE__ and __TIME__. They are converted to char arrays (strings, basically) at the time the compiler is run. You can store them directly to EEPROM, or use some sort of hash to convert it to a convenient number to store instead. Then, whenever the code boots, compare the stored value with the one computed from the values coded into the program. If they differ, overwrite the stored value with the new one and execute the run-once code.
Something along the lines of 
byte i=0;
char checkVal[]=__TIME__ __DATE__;
for (int j=0; j<strlen(checkVal); j++){
  i+=(byte)checkVal[j];//Creates a modulo 256 sum of the ASCII values of the chars (really poor hash)
}
if(EEPROM.read(26)!=i){//stored EEPROM location (arbitrary) -- feel free to use wear leveling, though, or some other method
  //DO RUN-ONCE CODE HERE
  EEPROM.write(26,i);//store the new value to stop it running again
}


user37622: This is a X->Y problem. Here is a solution for X:
Bit 3 of high fuse of the ATmega328p controls if EEPROM memory is preserved through the chip erase. You can change the high fuse setting in boards.txt. Restart the IDE to apply the new setting.
The fuses are written when you select the "burn bootloader" option in the Arduino IDE.

50183: <p>I'm using EEPROM to store project settings non-volatile.
After reuploading the sketch to my board (over SPI via ArduinoISP), the EEPROM is reset to full <code>0xFF</code>s and I have to manually do a "software reset" with a second switch, which initializes the EEPROM with its default values.</p>

<p><strong>Is it possible to run a segment of code once, and only once, after booting up the first time after being programmed?</strong></p>

<p>I'm working around it by checking whether a piece of EEPROM is <code>1</code> at startup when it would always be <code>0</code> after the initialization and during usage, but surely there's a cleaner alternative than checking for an EEPROM bit each time.</p>
 47164: <p>I've actually done some tinkering with this sort of thing, or alternatively how to ensure previous EEPROM (or similar) settings are formatted on upload of a new sketch.</p>

<p>There are two values (C macros, in this case) that are baked into a program when it is compiled (for Arduino, the program is recompiled on each upload) that can be used to tell if the programming is "fresh."</p>

<p>The values you'd want are <code>__DATE__</code> and <code>__TIME__</code>. They are converted to char arrays (strings, basically) at the time the compiler is run. You can store them directly to EEPROM, or use some sort of hash to convert it to a convenient number to store instead. Then, whenever the code boots, compare the stored value with the one computed from the values coded into the program. If they <em>differ</em>, overwrite the stored value with the new one and execute the run-once code.</p>

<p>Something along the lines of </p>

<pre><code>byte i=0;
char checkVal[]=__TIME__ __DATE__;
for (int j=0; j&lt;strlen(checkVal); j++){
  i+=(byte)checkVal[j];//Creates a modulo 256 sum of the ASCII values of the chars (really poor hash)
}
if(EEPROM.read(26)!=i){//stored EEPROM location (arbitrary) -- feel free to use wear leveling, though, or some other method
  //DO RUN-ONCE CODE HERE
  EEPROM.write(26,i);//store the new value to stop it running again
}
</code></pre>
 37622: <p>This is a X->Y problem. Here is a solution for X:</p>

<p>Bit 3 of high fuse of the ATmega328p controls if EEPROM memory is preserved through the chip erase. You can change the high fuse setting in boards.txt. Restart the IDE to apply the new setting.</p>

<p>The fuses are written when you select the "burn bootloader" option in the Arduino IDE.</p>
