How to write and read the EEPROM?

Hi guys,

That´s my first post here so please, apologize me for the dumb question, i was looking for and i didn´t found it. :blush:

I need to get a number valor from the serial and save it in EEPROM and read it, same after arduino was restarted.

It´s like in shell script, you know:
number_serial > number.txt

cat number.txt > NUMBER01

Help me plz ^^

Help > Reference > Libraries > EEPROM

That´s what i need thk you =DDDD XD

But I´m with doubts in the exemple:
Example

#include <EEPROM.h>

void setup()
{
for (int i = 0; i < 512; i++)
EEPROM.write(i, i);
}

void loop()
{
}

I have that comes form serial (IRlib):
if (irrecv.decode(&results)) { // IR
Serial.println(results.value); // IR
irrecv.resume(); // IR

IRr = (results.value * 1);
Serial.println(IRr );

How can I write IRr valor in the EEPROM?

Like this?
EEPROM.write(i, IRr);
:cold_sweat:

That are the kind of values that I need to storage:

IRn2= 13646
3843765582
IRr= 13646
IRn= 13646

other exemple:
IRn2= 13646
1825097194
IRr= -14870
IRn= 13646

The EEPROM library only deals with bytes. There are several approaches to handle longer data types. For example: (1) Reduced the longer types to byte values using bit shift operations, (2) Use UNION to access the individual bytes in longer data types, (3) Use the eeprom_write_* and eeprom_read_* functions defined in AVR-Libc. Here is an example of the latter. Note there are also functions for double words (32-bit integers), blocks, and bytes.

#include <avr/eeprom.h>      //http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html
#include <EEPROM.h>          //http://arduino.cc/en/Reference/EEPROM
#include <Streaming.h>       //http://arduiniana.org/libraries/streaming/

int myInt1, myInt2;          //note that a 16-bit int is also referred to as a word
float myFloat1, myFloat2;    //floats require 32 bits

void setup(void)
{
    delay(2000);
    Serial.begin(115200);
    myInt1 = 31416;
    myFloat1 = 3.14159;
    eeprom_write_word( (uint16_t *) 10, myInt1 );    //write a 16-bit int to EEPROM address 10
    eeprom_write_float( (float *) 20, myFloat1 );    //write a float to address 20
    myInt2 = eeprom_read_word( (uint16_t *) 10 );    //read a 16-bit int from address 10
    myFloat2 = eeprom_read_float( (float *) 20 );    //read a float from address 20
    Serial << _DEC(myInt2) << endl;                  //print the values read
    Serial << _FLOAT(myFloat2, 5) << endl;
}

void loop(void)
{
}

We have the same topic I think. It might help.
http://arduino.cc/forum/index.php/topic,152977.0.html

Jack, how do I get that? #include <avr/eeprom.h> //avr-libc: <avr/eeprom.h>: EEPROM handling

I just found that:

http://download.savannah.gnu.org/releases/avr-libc/

=/

danielbcjr:
Jack, how do I get that? #include <avr/eeprom.h> //avr-libc: <avr/eeprom.h>: EEPROM handling

It's already there, just type it in. The code I posted above should compile and run fine. AVR-Libc is part of the Arduino toolchain.

IT WORKS =DDDDDDD

thanks formal => http://babuino.info/post/45239830057/gravar-dados-na-eeprom-do-arduino-dados-de-ate-16-e-32

Has Google Translate plugin if you want to read ^ ^

danielbcjr:
IT WORKS =DDDDDDD

thanks formal => http://babuino.info/post/45239830057/gravar-dados-na-eeprom-do-arduino-dados-de-ate-16-e-32

Has Google Translate plugin if you want to read ^ ^

Nice site, and thanks for the kudos :smiley:

Check the Arduino Reference, it explains the steps nice and clear :slight_smile:

http://arduino.cc/en/Reference/EEPROMRead - Read
http://arduino.cc/en/Reference/EEPROMWrite - Write