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
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
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.
Will go with SPIFFS then!
Cheers from the Argentinian vacationer who carries an ESP32 plus notebook…
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!
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
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…