Storing in EEPROM memory

Hello everybody,

Storing char or String in EEPROM

Thanks

The docs are your friend. EEPROM can be unintuitive, give 'em a read!
https://www.arduino.cc/en/Reference/EEPROM

If you are storing a single int value, it should be something like

#include <EEPROM.h>

int addr = 0;  // EEPROM address (location where int is stored

void setup() {
  ...
}

void loop() {
  ...
  int val = 58;             // get your integer value
  EEPROM.write(addr, val);  // write the integer value to EEPROM address
}

That's preety easy. But, the problem is that I need to store a string value to the EEPROM

Read the docs. It can be done.

My friend If I can did it alone, I wouldn't ask here from the first place. I have read it before even writing this problem and tried it so many times without any result. So please if you don't want to help just be silent and let other help.

Nice response when I just tried to help you.

Your OP specifically asked to store an INT.

My friend, I know how to store an integer before writing this problem, my problem is that I want to store a string inside the EEPROM and I don't know hot to do that.

I need to store a string value like "130 207 95 100" to the EEPROM

It's not clear if you have a String object (capital 'S') or c-string (small letter 's' null terminated character array).

You can not store the String object, but you can store the underlying character array with eeprom.put().

To extract the underlying character array if you have a String object, you can use the .toCharArray() String function.

It is capital String, I found a way to convert it to a unsigned long but couldn't also save it to the EEPROM.

Any help with that?

Please post some simple code which shows what you are doing.
It should be straightforward to use EEPROM.put() and EEPROM.get() with an unsigned long.

Store it character-by-character?

void store(int address, String s)
{
   int len = s.length();
   for (int i=0; i<len; i++)
     EEPROM[address+i] = s[i];
   EEPROM[address+len] = '\0';  // Add a null terminator
}

Thank you so much, I have solved the problem appreciate your attention to help

Thanks, I have selected your reply as a solution

I apologize for any negative behavior or miss communication. I was upset that night.

1 Like

Spoken like a man. Apology accepted.

I see you have a solution.
Best of luck!