Arrays don't retain data on power down

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Frank87a
 
Posts: 18
Joined: Fri Apr 13, 2018 2:47 pm

Arrays don't retain data on power down

Post by Frank87a »

A bit new at this. Are arrays supposed to retain data when the 32U4 is powered down? I am using four arrays with 10 cells each. Can get the data into the arrays just fine, but loose it when powering down. There are a couple of other problems, but if this one can't be solved there is no use going further.

Any suggestions appreciated,
Frank

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Arrays don't retain data on power down

Post by adafruit_support_carter »

In general, no. They are typically stored in volatile memory, so will disappear when power is removed (that's the volatile part). If you want the data to persist between power cycles, you will need to store it in some form of non-volatile memory. The 32u4's have a limited amount of EEPROM you may be able to use:
https://learn.adafruit.com/memories-of- ... ino/eeprom

User avatar
Frank87a
 
Posts: 18
Joined: Fri Apr 13, 2018 2:47 pm

Re: Arrays don't retain data on power down

Post by Frank87a »

I went to the Arduino Reference and don't see the ATmrga32u4 listed as a compatible device. just want to make sure that the " #include <EEPROM.h> will work with the 32u4 before I try and figure out how to use it. Will the EEPROM library work with the 32u4?
Thanks, Frank

EEPROM Library
The microcontroller on the Arduino and Genuino AVR based board has 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.

The supported micro-controllers on the various Arduino and Genuino boards have different amounts of EEPROM: 1024 bytes on the ATmega328P, 512 bytes on the ATmega168 and ATmega8, 4 KB (4096 bytes) on the ATmega1280 and ATmega2560. The Arduino and Genuino 101 boards have an emulated EEPROM space of 1024 bytes.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Arrays don't retain data on power down

Post by adafruit_support_carter »

Should work. Here's an example that uses EEPROM on a 32u4:
https://learn.adafruit.com/how-cold-is- ... ure-logger

User avatar
Frank87a
 
Posts: 18
Joined: Fri Apr 13, 2018 2:47 pm

Re: Arrays don't retain data on power down

Post by Frank87a »

Haven't tried to use the <EEPROM.h> function yet. My question is, do I need to provide the .>= 3.3 msec delays for each byte that I write or does <EEPROM.h> some how take care of it?
Thanks Frank

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Arrays don't retain data on power down

Post by adafruit_support_carter »

Check out the logger source code from that guide.

User avatar
Frank87a
 
Posts: 18
Joined: Fri Apr 13, 2018 2:47 pm

Re: Arrays don't retain data on power down

Post by Frank87a »

[The extension ino has been deactivated and can no longer be displayed.]

Four 10 element arrays , ant1 ,ant2,ant3 and ant4, Lines 800-815.

Two different EEPROM write candidates. lines 800-806 and 809-815

Lines 800-806 compile with no errors. If this method is a valid way to save the arrays on power down, then I would simply read the EEPROM back to the arrays like, ant1 = EEPROM....etc. on power up.

lines 809-814 will not compile when using "EEPROM.write. line 811.
The error message from line 811 was "no matching function for call to EEROMClass::write(int&)"
I saw the "::" in the error message and substituted that for the "." after the write and
lines 812-814 seem to compile OK, no matter how many colons I put in there.. Don't know if anything useful will result. Tried to find the meaning of "::" in the Arduino Ref but could't find it. If this method is workable, then I think I should have the choice of reading the data directly from EEPROM easily, or reading it back to the arrays on power up.

My question is, will either of these approaches work?

Any direction here on which method is would be appreciated.
Nothing tested yet. Would need to write some code to avoid getting into a EEPROM write loop.
Thanks - Frank
Sorry my file structure would not allow me to send the entire file at this time.

800 for (int i=0; i<= 9; i++) // There are 10 cells/array
{
EEPROM[0+i]=ant1;
EEPROM[10+i]=ant2;
EEPROM[20+i]=ant3;
EEPROM[30+i]=ant4;
806 }


809 for (int i=0; i<= 9; i++)
{
EEPROM.write(EEPant1=ant1);
EEPROM:::write(EEPant2=ant2);
EEPROM::write(EEPant3=ant3);
EEPROM:write(EEPant4[i]=ant4[i]);
815 }
Attachments

[The extension ino has been deactivated and can no longer be displayed.]


User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Arrays don't retain data on power down

Post by adafruit_support_carter »

See code linked above for example of how to read and write to EEPROM. The library documentation is also good:
https://www.arduino.cc/en/Reference/EEPROM

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”