Problem with EEPROM Storage

I have been working on EEPROM to store the String object using EEPROM.put().
1>I’m using String temp to store temporary String and it will get erased during reset.
2>program uses String named Stored_number to update the EEPROM using EEPROM.put() and it can be accessed after reset.
3>I will be providing String temp and stored_number using Serial monitor.
4>temp string Serial data will be like ==> +12345;
5>stored_number string Serial data ==> -67890;
6>Program will only update EEPROM when it receives Stored_number data

BUG the facing is ==>> EEPROM is getting updated when it receives temp data
i will be using function reset() to reset arduino using software and it will work fine no issue with that

PLEASE HELP

thanks in advance

program code<<<<<<<<<<<<<<<<<<<<<<<<<

#include <EEPROM.h>
String stored_number="";//String need to be stored in eeprom
String temp="";//stores temporary data

void setup()
{
EEPROM.get(0,stored_number);//get eeprom value at zero location and save it in stored_number
Serial.begin(9600);
delay(100);
}
void(* reset) (void)=0;

void loop()
{
Serial.print(“stored_number=”);
Serial.println(stored_number);
Serial.print(“temporary=”);
Serial.println(temp);
Serial.println("----------");
delay(1000);
}

void serialEvent()
{
char c=Serial.read();//read serail data into variable c
if(c==’+’)//whether to check temp or Stored_number
temp=Serial.readStringUntil(’;’);//read serial data to temp
if(c==’-’)//whether to check temp or Stored_number
{
stored_number=Serial.readStringUntil(’;’);
EEPROM.put(0,stored_number);//Updates the eeprom
delay(1000);
reset();
}
}

You are only storing a pointer to the String object in EEPROM. The pointer does not hold the actual data, which is located in RAM. It only indicates where in RAM it is stored.

while I'm here...can someone explain this to me

void(* reset) (void)=0;

a void pointer names reset, then a typecast of nothing to void, all set to 0?!?! What does this mean?

EDIT: Oh...I see, it is a pointer to a function with no arguments and returns nothing named reset and it is pointing at address 0?

check this link for details http://www.instructables.com/id/two-ways-to-reset-arduino-in-software/?ALLSTEPS

Don't even attempt to store String objects into EEPROM. They use pointers and the pointers won't be valid next time. You can store an array of char.

thanks for advice …

can i store complete array of characters like c[15] in EEPROM single storage space??
and how to retrive it??

Storing a 15 character array will require 15 bytes of storage space.

You can use EEPROM.write in a loop, incrementing the address every time till you reach 15.

You can read it back by reading the 15 locations one by one using EEPROM.read

GaganDeepakR: thanks for advice ...

can i store complete array of characters like c[15] in EEPROM single storage space?? and how to retrive it??

Yes, I do that to store and retrieve a file name.

Use eeprom_write_block to write it and eeprom_read_block to read it back.

sterretje: Storing a 15 character array will require 15 bytes of storage space.

You can use EEPROM.write in a loop, incrementing the address every time till you reach 15.

You can read it back by reading the 15 locations one by one using EEPROM.read

If you are using an array, you can read/write it in one call:

char arr[15] = "Some Text";

//Write array to address zero
EEPROM.put( 0, arr );

//Read array from address zero
EEPROM.get( 0, arr );

@pYro_65

Thanks for that; my C++ knowledge is not good enough to understand that part of the library completely. I know one can do structs and floats etc but never considered arrays of bytes.

sterretje: @pYro_65

Thanks for that; my C++ knowledge is not good enough to understand that part of the library completely. I know one can do structs and floats etc but never considered arrays of bytes.

No worries, it will also do arrays of any data type, not just bytes.

Thank you every one for helping ... i used EEPROM.put() to store char array and it works for me.. and i can access it using EEPROM.get()...

I need to know how to use watch dog timer ..please help regarding it

Thank u

I suggest that you start a new thread for that as there is no relation with the eeprom.