• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Storing arrays in EEPROM – ESP32 is possible?

Q&A Forum › Category: ESP32 › Storing arrays in EEPROM – ESP32 is possible?
0 Vote Up Vote Down
Marcelo Miguel asked 4 years ago

Hello there!
Is the Argentinian menace again!
Let say I want to store 3 arrays in EEPROM, which are:

int array_temperature [128];
int array_humidity [128];
int array_pressure [128];

So any data stored there can be retrieved in case of ESP32 power failure.
Each data is stored on each position at regular intervals, lets say 10 minutes.
Is this possible?
Thanks!
Marcelo

Question Tags: ESP32
9 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.

Yes, it is possible to store arrays in EEPROM.
You can take a look at this article that explains it in great detail:

– https://roboticsbackend.com/arduino-store-array-into-eeprom/

Have you considered using SPIFFS instead? Basically, creating a .txt file in the flash memory where you save your data.

– https://randomnerdtutorials.com/install-esp32-filesystem-uploader-arduino-ide/

If you need to save data permanently very frequently, there’s also the option to use a microSD card.

– https://randomnerdtutorials.com/esp32-microsd-card-arduino/

 

I hope this helps

Regards,
Sara

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

I would recommend NOT using EEPROM for transient data like this. The EEPROM only has a limited number of write cycles before corruption can occur.
 
As Sara says, use SPIFFS or SD card instead.

0 Vote Up Vote Down
Marcelo Miguel answered 4 years ago

Will go with SPIFFS then!
Cheers from the Argentinian vacationer who carries an ESP32 plus notebook…

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Have a great vacation!
 

0 Vote Up Vote Down
Marcelo Miguel answered 4 years ago

https://github.com/TenoTrash/Portable_wheather_ESP32
Well, I’m not that far I believe.
Still confused on how to store/read SPIFFS file to array, but pretty close!
Cheers!

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
Let me know if you have specific questions.
Regards,
Sara

0 Vote Up Vote Down
Marcelo Miguel answered 4 years ago

Thanks! I’m a little stuck here. I have three files in SPIFFS that (I try) to store three arrays.

My arrays:

int array_temperature [128];
int array_humidity [128];
int array_pressure [128];

To store them I use:

void write_arrays() {

file_temperature = SPIFFS.open(file_temperature_path, FILE_WRITE);
file_humidity = SPIFFS.open(file_humidity_path, FILE_WRITE);
file_pressure = SPIFFS.open(file_pressure_path, FILE_WRITE);

for (int n = 0; n <= 128; n++) {
file_temperature.println(array_temperature[n]);
}
for (int n = 0; n <= 128; n++) {
file_humidity.println(array_humidity[n]);
}
for (int n = 0; n <= 128; n++) {
file_pressure.println(array_pressure[n]);
}

file_temperature.close();
file_humidity.close();
file_pressure.close();

Serial.println("Se han guardado las arrays en la SPIFFS");
}

And to read them (when I power up the ESP32) I use:

void read_arrays() {

file_temperature = SPIFFS.open(file_temperature_path, FILE_READ);
file_humidity = SPIFFS.open(file_humidity_path, FILE_READ);
file_pressure = SPIFFS.open(file_pressure_path, FILE_READ);

String string_temperature;
String string_humidity;
String string_pressure;

int counter = 0;
while (file_temperature.available()) {
string_temperature = file_temperature.readStringUntil('\n');
array_temperature[counter] = string_temperature.toInt();
counter++;
}

counter = 0;
while (file_humidity.available()) {
string_humidity = file_humidity.readStringUntil('\n');
array_humidity[counter] = string_humidity.toInt();
counter++;
}

counter = 0;
while (file_pressure.available()) {
string_pressure = file_pressure.readStringUntil('\n');
array_pressure[counter] = string_pressure.toInt();
counter++;
}

file_temperature.close();
file_humidity.close();
file_pressure.close();

Serial.println("Arrays llenas con datos anteriores");

}

And… it does not work, maybe I’m storing them wrong? Or read them wrong?
Thanks in advance!
Marcelo from Argentina

0 Vote Up Vote Down
Marcelo Miguel answered 4 years ago

Aha!

Re-reading my own code, seems to need \r instead \n on each readStringUntil('\n');

So:

string_pressure = file_pressure.readStringUntil('\r');

Seems to work…

1 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
I’m glad you figured it out.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.