Pages: [1]   Go Down
Author Topic: How to write and read the EEPROM?  (Read 1758 times)
0 Members and 1 Guest are viewing this topic.
São Paulo
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-red

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


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Help > Reference > Libraries > EEPROM
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

São Paulo
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That´s what i need thk you =DDDD  smiley-lol

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);
  smiley-roll-sweat
Logged


São Paulo
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

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

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

São Paulo
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Jack, how do I get that? #include <avr/eeprom.h>      //http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html

I just found that:

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

=/
Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Jack, how do I get that? #include <avr/eeprom.h>      //http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html

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

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

São Paulo
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ^ ^

Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

New York, NY
Offline Offline
Full Member
***
Karma: 2
Posts: 142
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check the Arduino Reference, it explains the steps nice and clear smiley

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

Arduino Uno R3
Teensy 3.0
Mac OSX Yosemite

Pages: [1]   Go Up
Jump to: