3

I am relatively new to Arduino and I am currently writing some code to control a relay board. The on/off times are provided by the user at run-time and should be stored persistently (EEPROM or flash) in case of power-down.

On my Uno I worked with the EEPROMex library and that worked well. Now I have a Due which doesnt have any EEPROM and I am struggling how to store variables persistently. Specifically, I dont know how to access whatever I wrote to the flash memory previously. In the example below the content of test[] is obviously overwritten on every restart.

PROGMEM int test[] = {1, 2, 3, 123, 23};

void test()
{
  Serial.println((long)test);
  for (int i = 0; i < 5; i++)
  {
    Serial.println(test[i]++);
  }
}

I noticed that the address does not change during re-starts, so I I tried reading/writing beyond index 4. This out-of-bounds read/write worked, I guess since I am anyway not storing anything else. Interestingly even this memory which is out of the array is overwritten on power-up.

So: How do I store on unser input data (variables) persistenly on an Arduino due without using any shields?

Cheers, Sebastian

  • You don't need a whole shield for EEPROM. Just 4 or 5 wires and an EEPROM DIP-chip. – Gerben Jul 1 '15 at 12:52
2

I really hope that somebody knows differently, but I'm fairly sure that the answer is that you can't directly save runtime data back to the Arduino Due board. I've looked into this myself and have only found answers saying "wire up an external EEPROM" or similar. Whilst it seems that it should be technically possible to write into unused (or pre-reserved) areas of the program memory, I suspect that the CPU has to be put into a special mode to do this, which is very probably only possible from the bootloader when flashing a new program to it.

I've chosen to go with FRAM chips for data storage. Link to mine. They are difficult to wire up - the only ones I found were in surface mount packages (although some hobby retailers sell them mounted to little boards with header pins), but they are very cheap, very durable (you can write to them a great number of times before they wear out), operate at high speeds and you can read/write single bytes from/to them. Other storage chips often require you to write whole "pages" of data at a time which can mean reading in the existing data, modifying it, then writing it back.

Additional comments: In your original question, you state that the contents of your PROGMEM located array must be restored on restarts. I don't think this is the case. That would suggest that the contents are stored elsewhere and code is in place to overwrite them, however it could be the case that they are copied into working RAM, which would mean that the PROGMEM macro is not actually doing anything on the Due - which may well be the case.

Modify your code to change one of the values of the array (within the bounds of the array!) and then print its value out again after changing it. If the value printed has changed then this means that PROGMEM is not actually doing what it is supposed to do on the Due, which would be a real shame.

  • Adafruit sells FRAM on a breakout board which is a lot easier to deal with when everything else is thru-hole. Plus FRAM are crazy fast compared to EEPROM. – JRobert Jul 1 '15 at 15:29
1

Without an external device you won't be able to store data permanently. So it might not be a full shield, but you'll have to add SOMETHING. Depending on how much data you need you might use components that have EEPROM as a side feature. For instance, as explained here, the DS1337 RTC module has 56 spare bytes of EEPROM^H^H^H^H^H^H Non-Volatile RAM available. I know, it sure isn't much, BUT it might be enough for your needs, depending on how much you need to store.

And of course it provides you with DateTime capabilities, wich could come in handy.

Aside from this, there are EEPROM chips mounted on a small board, with DIP switches to set the I2C address, which would be very discrete, and could store a large amount of data. See this one for instance.

  • 1
    Technically the DS1337 memory is not called EEPROM, but battery backed RAM. You can abuse the alarm sections to get an additional 7 bytes :-). I used this trick on the DS3231 which doesn't have any 'free memory'. – Gerben Jul 1 '15 at 12:49
  • You're right. The datasheet says "56-byte, battery-backed, nonvolatile (NV) RAM for data storage". Neat trick you did abusing the alarm section ;-) – dda Jul 2 '15 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.