-1

I have been writing lots of different kinds of Sketches for Arduino, but there is something I have not heard if it is possible.

I would like to be able to get an Arduino to save preferences that can be restored back when the Arduino restarts. The kind of data that you want to change (in the field) without having to hardcode it in the sketch, or needing to upload changes from the IDE.

Examples:

  • Thermostat settings
  • Time lapse camera frame rate

So if I set the thermostat for 68° and the power goes out, I want it to remember what temperature I set when the power comes back on.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
B. Taylor
  • 1
  • 1

2 Answers2

2

Unless you have a large amount of settings that you wish to save, EEPROM should suffice for your purposes. What I would do is define a struct to store the relevant options, and use the EEPROM library to read/write the entire struct.

A wonderful example of how to do that exists on the Arduino reference pages: EEPROM Put

I was hoping to do some kind of open file, read/write operation like you can do in php, where I can read/write whole strings at a time

There is really no need to do this unless you have a large amount of options. Otherwise your best bet is to use something like an SD card, which does support FileIO operations

George Troulis
  • 168
  • 2
  • 9
1

Seems you looking for Arduino EEPROM

EEPROM: memory whose values are kept when the board is turned off (like a tiny hard drive). This library enables you to read and write those bytes.

Jed Hodson
  • 44
  • 7
  • Thanks for the EEPROM info, but I was hoping to do some kind of open file, read/write operation like you can do in php, where I can read/write whole strings at a time.. or is that done with something like serial.print (temperature); where I would be saving the temperature as a string to the EEPROM? – B. Taylor Aug 27 '18 at 19:07
  • B. Taylor Then maybe adding an SD card is another option. The Arduino is rather limited in regards to persistent storage – Jed Hodson Aug 27 '18 at 21:49