Store variable in PROGMEM -- survive resets?

Hi all,

I'm looking into PROGMEM programming, should be doable, however I have a specific requirement: I would like to be able to change the value of the variable (in this case, an integer) at run-time in such a way that it survives a board reset. It thus definitely need to be in flash mem, but the PROGMEM examples all seem to talk about consts.

Thanks!

It thus definitely need to be in flash mem

Try EEPROM instead - it is very difficult to write to progmem from a non-boot sector program.

Like AWOL said, use EEPROM for storing data to survive power loss.

It does have a million read/write cycle limit (at least) but that would not normally cause a problem.

Mowcius

Exactly what I was looking for, thank you for your replies!

...but isnt the eeprom cleared when uploading a new sketch?

No. I think, that's exacly what the eeprom is for. :slight_smile:

No. I think, that's exacly what the eeprom is for

Correct. The RAM is cleared on boot but the EEPROM is stored until it is wiped.

Mowcius

i wish i could test, but i think i remeber that eeprom was wiped when the sketch is uploaded?

EEPROM is only wiped if you upload and run a Sketch that wipes it.

EEPROM is only wiped if you upload and run a Sketch that wipes it.

I presume someone can confirm it but that was what I thought also. If you are wanting to upload new sketches and keep the same number data then maybe SD is a better way to go as well.
Just out of interest, what are you wanting to store and recall on different sketches?

Mowcius

What's the big deal?
The OP only asked if it would survive a reset - s/he didn't mention reprogramming.

What's the big deal?
The OP only asked if it would survive a reset - s/he didn't mention reprogramming.

:o

Bit of thread lengthening that's all ;D

Currently, EEPROM is not touched when uploading a new sketch through the bootloader, and it also survives resets.

Just out of interest, what are you wanting to store and recall on different sketches?

I was doing run-dead battery tests. I had three (very simple) Sketches...

  • Clear the EEPROM
  • Run the test storing the results into the EEPROM
  • Send the contents of EEPROM to Serial

I used the Arduino monitor to capture the data and then copied it into Excel for further work.

Did you think of sending the data to an SD card as .csv (.txt and change it on pc) to make it easy to open on in Excel?
Then you could just wipe the SD card instead of clearing EEPROM.

Mowcius

That's a good suggestion but...

  • In this case it would have been too much investment in time and materials. I needed something quick and simple to determine if the application would work on batteries.
  • The SD card and supporting circuitry would consume energy reducing the run time. I wanted the test to be as close as possible to the final application.
  • I wanted to get some experience using the EEPROM library.