Go Down

Topic: newbie question: how to store data ? (Read 362 times) previous topic - next topic

M4vrick

Hello :)

I'm a little bit confused about how to store data to keep them after power off.

I've seen write() and read() command, but it seem to be able to write only a single byte.
I need to store only 3 int, so 6 byte right ?

Is there any way to split an int to 2 byte to store them ? and do the reverse after read ?

Any other way? Maybe with PROGMEM but I did'nt understand how to use it ...

thank you

Arrch


Is there any way to split an int to 2 byte to store them ? and do the reverse after read ?


See highByte() and lowByte()

Using a union might also make sense.

retrolefty


Hello :)

I'm a little bit confused about how to store data to keep them after power off.

I've seen write() and read() command, but it seem to be able to write only a single byte.
I need to store only 3 int, so 6 byte right ?

Is there any way to split an int to 2 byte to store them ? and do the reverse after read ?

Any other way? Maybe with PROGMEM but I did'nt understand how to use it ...

thank you


To store data that is created while your sketch is running from a power off/on cycle the data must be written to the EEPROM memory only before the board is powered off. You can read and write any kind of data to EEPROM by using a proper user defined function or imported EEPROM library function. Here is one example of such a library:

http://playground.arduino.cc/Code/EEPROMWriteAnything

Lefty

UKHeliBob

To store data so that it available after a reset or powering off the Arduino you need to write it to non volatile memory.  This means either using the limited amount of EEPROM built into the Arduino or an SD card, which can hold much more.  Using EEPROM does not require any extra hardware but each byte of such memory can only be written to a fixed number of times before you might begin to see problems.

How much data do you need to store and how often is it likely to change ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

M4vrick

I know the limits of read/write for this kind of memory :)

I only need to store 3 int for the configuration, and there will be only very few changes.

The way explain on the playground seems to be exactly what I need :D

M4vrick

well well well ...

I've made the EEPROMAnything.h but the fonction EEPROM_readAnything is not recognized when I'm trying to compile the sketch.

"error: 'EEPROM_readAnything' was not declared in this scope"

The .h file is stored in the same place as other libraries, with it's own subfolder.

Code: [Select]
#include <EEPROM.h>
#include <EEPROMAnything.h>


int valeur1=0;
int valeur2=0;

struct config_t
{
int valeur1;
int valeur2;
} configuration;

void setup(){
   EEPROM_readAnything(0, configuration);
}

void loop(){
   
}

UKHeliBob

Quote
The .h file is stored in the same place as other libraries, with it's own subfolder.

There are at least 2 places where 'other libraries' are stored.  Were exactly have you put this library folder ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

M4vrick

#7
Feb 25, 2013, 06:53 pm Last Edit: Feb 25, 2013, 06:54 pm by M4vrick Reason: 1
in:

My documents/Arduino/Libraries

This is where I've put the other libraries I'm using.

EDIT: It's working after restarting the IDE  :smiley-red:

Go Up