Pages: [1]   Go Down
Author Topic: newbie question: how to store data ?  (Read 344 times)
0 Members and 1 Guest are viewing this topic.
Paris, France
Offline Offline
Newbie
*
Karma: 1
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello smiley

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
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello smiley

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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4257
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Paris, France
Offline Offline
Newbie
*
Karma: 1
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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 smiley-grin
Logged

Paris, France
Offline Offline
Newbie
*
Karma: 1
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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(){
   
 }
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4257
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Paris, France
Offline Offline
Newbie
*
Karma: 1
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 25, 2013, 12:54:42 pm by M4vrick » Logged

Pages: [1]   Go Up
Jump to: