Go Down

Topic: EEPROM reading - writing string[SOLVED]! (Read 7646 times) previous topic - next topic

sirus

May 26, 2012, 05:26 pm Last Edit: May 31, 2012, 11:14 am by sirus Reason: 1
Hello everyone!I'm trying to learn but i found enough difficulties about this board.Especially i 've got difficulties because i can't debug my code.
Could you help me for something?How can i write a string into the eeprom and after that how can i read it from memory???

Can you propose me any good website or book to make a start??

Thanks a lot!

johnwasser

http://arduino.cc/en/Reference/EEPROM

Use EEPROM one byte at a time, like Serial.read().
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

sirus

Thanks for your reply!Be the way have you got anyone an example which can helps someone to store string char by char ( each byte per time ).

That will helps my job a lot !

Thanks

sirus

#3
May 29, 2012, 11:46 am Last Edit: May 29, 2012, 12:10 pm by sirus Reason: 1
I want to write 300 characters into eeprom.In order to do something like that should i follow something like that??
Code: [Select]

String inputString = "";
int cbytes = 0;
char inChar;
void writeEEPROM(){
 if(Serial.available()) {
     c = (char)Serial.read();
     EEPROM.write( cbytes++,(byte)inChar );
       
     if( c== '\0' )
       Serial.print("Success");  
 }
}  


The read process, if i want to took eeprom's data back??
Code: [Select]

void __read_EEPROM( )  {
 int _addrByte = 0;
 String str;
 int value;
 while( _addrByte++ != 300 )  {
   value = EEPROM.read( _addrByte );
    str += (char)(value);
   _addrByte++;  
 }
 Serial.print(str);
}

In terminal i take some results but my data are not return in the correct order, just i've send them....

Thanks!

johnwasser

When you are reading back from EEPROM you are incrementing the address twice:
Code: [Select]

void __read_EEPROM( )  {
  int _addrByte = 0;
  String str;
  int value;
  while( _addrByte++ != 300 )  {             //// HERE
    value = EEPROM.read( _addrByte );
     str += (char)(value);
    _addrByte++;                                 ///// And HERE
  }
  Serial.print(str);
}

Take the ++ off the first one.  You may also want to add:  if (value == 0) break; before str += (char)(value);.  That way you won't put all 300 characters into str even when the string is only 20 characters long.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

sirus

I've just seen it!
My mistake i'm sorry!

Thank you very much!

venado_bike

I've just seen it!
My mistake i'm sorry!

Thank you very much!
that type is the c variable? You could send the sketch?

samazw

So Sirus has his anser and it is no more interesting for him to respond to your request, Venado_bike.

That´s h ow life is today :-(

magickiyan

#8
Sep 08, 2018, 10:00 am Last Edit: Sep 08, 2018, 10:08 am by magickiyan
Hello everyone.
i trying  to save String data type in eeprom but i cant do it!
can you guide me . thanks alot.

PaulS

Hello everyone.
i trying  to save String data type in eeprom but i cant do it!
can you guide me . thanks alot.
You have some code? You forgot to post it, or explain what the problem is.
The art of getting good answers lies in asking good questions.

Go Up