Does void setup() get executed in the case of a power reset?

Happy thanksgiving everyone!

I've got a situation, and don't have my board available to test it out. In my project, the power to the Arduino (Due) will be supplied through a switch which will be being powered on and off regularly. Through this, there is just one int value which I need to save through the power outages and so I was planning to just set this value using PROGMEM in the setup, rather than having to read from flash every loop.

So my question is again, does void setup() get executed in the case of a power reset?

Also, I'm open to advice if you think there is a better way to save this int value!

Thanks,

Ameen

will be being powered on and off regularly

setup() runs on power up. Show us some code.

If the value never changes, you don't need to specifically save it in PROGMEM. for example,

define val 54

will always be part of your code, as will

int val2 = 15760;

and if either of those are used in setup(), they will always be used. They are definitely already in PROGMEM.

If, on the gripping hand, the value will change occasionally, it would be best stored in EEPROM.

And yes, code would be nice to see, so we can advise you on the best option(s).

Thanks for the help!

As for showing code, I’m not sure how much you want to see, essentially the part I’m interested in does something like:

#include <avr/pgmspace.h>

prog_uint16_t y;
int x = 0;

void setup()
{
x = pgm_read_word_near(y);
}
void loop()
{
x = //some value
PROGMEM y = x;
}

I wish I could use EEPROM but I’ve read that the Due board doesn’t support that function.

If you want to save the value when the Arduino is powered off, you need to write it to a persistent store such as the EEPROM. The PROGMEM attribute leaves your data in flash memory, which is inherently read-only at runtime.

I think you missed the important parts of my questions. Is the value to be saved ever changed? Changed very rarely? Changed often?

Just had a look at the Due. You can write to flash. In fact, someone has come up with a library that does just that. See the very recent thread at: http://forum.arduino.cc/index.php?action=search2

Be sure to visit his blog and Github repository.

Better still is the library that writes to the EEPROM on the Due board in one of the support chips.

Grumpy_Mike: Better still is the library that writes to the EEPROM on the Due board in one of the support chips.

That would be better, but I could not see any reference to EEPROM available on the Due board. Reference?