Go Down

Topic: eeprom string storage (Read 337 times) previous topic - next topic

rodrigo_cirilo

Hello people.

I need some help, I will have to store many 9 character strings example (234597801, 675789501, 657896510) are ID coming from an external equipment.

So I need to store many of these numbers using the smallest eeprom address number, I use esp8266 with 4096 eerpom addresses, however if I write one character to each address I will have 455 ID's saved but I need to store more values as I could do that?

thanks in advance

Whandall

9 decimal digit chars represent a range from 0 to 999999999.
Ther range of an unsigned 32 bit integer is  0 to 4294967295.

Convert your numbers to uint32_t (strtoul) and you can store 1024 ids.

If you need more, add EEPROM or FRAM or a SD.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

rodrigo_cirilo

Ok, thanks for the reply.

But could you give me an example, or if I need some special library.

Whandall

What did google tell you about 'strtoul'?

Use EEPROM.put() and EEPROM.get() to store and retrieve the values.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

rodrigo_cirilo

Sorry, I googled, but that's too much for me.

I'll wait if someone can post a simple example of how to do

dougp

Sorry, I googled, but that's too much for me.

I'll wait if someone can post a simple example of how to do
While you're waiting use your time productively and peruse the Arduino reference and playground.  Maybe do a site search on 'eeprom'.

Just sayin'.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

Whandall

Sorry, I googled, but that's too much for me.

I'll wait if someone can post a simple example of how to do
You know that brains atrophy if they are not used?
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

rodrigo_cirilo

haha ha. Yes I know..

It's just that I'm programming both for ESP and for an app, there will be communication between them.

Anyway, now I will not have time to analyze and test everything I have available, in C for PIC (microchip) I know how to do this, I used a lot already, but now in Arduino IDE I am time this problem.

If it's easy for you to put a simple example of how to do it, I'd be grateful, but if it's hard work you can let me turn around and run after the information.

Whandall

I gave you massive hints, if that is not enough to write the code, you will have to look up the three functions.

And no, I don't support copy and paste programmers.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

rodrigo_cirilo

Yes I do not support either, I usually take examples and modify my need.

However, I saw a lot of material available in English, I am Brazilian, and my English is very beginner, I confuse myself with words, so it is a little complicated to understand all material available on the Internet.

However I thought of a way to continue taking up less eeprom space, I'll take the ID (string) split into 5 2-character strings (45, 68, 89 for example) then convert to byte, then instead of occupying 9 addresses. eeprom to save each ID, I would only occupy 5.

It may not be the best option, but so I think I can do it, realize that it is not lack of willpower, it is by not knowing the correct paths and a simple example would help me to follow the best path.

Whandall

I gave you massive hints, if that is not enough to write the code, you will have to look up the three functions.
You don't need to excuse your lazyness.

Don't whine, look up the three functions you were hinted to use, I'm shure each one comes with an example.

I will not comment your alternative strategy.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

GolamMostafa

#11
Aug 30, 2019, 03:31 pm Last Edit: Aug 30, 2019, 05:57 pm by GolamMostafa
1.  Let us take one string: 234597801

2.  Memory mapping of string of Step-1 is: 32 33 34 35 39 37 38 30 31 (spaces are for clarity).

3.  You want to save it into EEPROM of ESP using minimum locations --
(1)  Normal storage of the data of Step-2 would require: 9 locations.
(2)  Equivalent integer (234597801 ==> 0x0DFBADA9) would require: 4 locations.
(3)  Convert string data of Step-2 into unsigned long integer data:
Code: [Select]
void setup()
{
  Serial.begin(9600);
  char myData[] = "234597801";
  
  unsigned long x = strtoul(myData, nullptr, 10);
  Serial.print(x, HEX);  //shows: DFBADA9 => 0DFBADA9
}

void loop()
{
 
}


4.  Store 4-byte data of Step-3(2) into internal EEPROM (starting at location 0x0010) of ESP8266 using codes to be written by OP. (My codes read back 0. Have data been written?)

GolamMostafa

#12
Aug 30, 2019, 03:51 pm Last Edit: Aug 30, 2019, 03:53 pm by GolamMostafa
Use EEPROM.put() and EEPROM.get() to store and retrieve the values.
Do they work in ESP8266?

Whandall

Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

GolamMostafa

#14
Aug 30, 2019, 05:55 pm Last Edit: Aug 30, 2019, 06:00 pm by GolamMostafa
Where did you read they don't?
Or did I experiment with ESP8266? My result of experiment has many supportive posts in the web.

Go Up