Hi,
I am using a custom board which features an ESP32-S3 for my thesis. I am saving a vector of measurement data in a matrix using the preferences.h library. i worked fine until after roughly 40 saves, now wont i save anything new. I first thought that i migh be a problem with the key, value pair designation, but after some testing have i found that it does not overwrite already save values. Which it did before.
the project utilizes many custom libraries. so i Will link the github containing the whole project.
Hi,
why are you permanently initializing the display? You can't see exactly what you are doing with Preferences. Hint. Reduce the sketch to the bare minimum that still shows the problem.
Can you write a small test with the Preferences ?
If you test that extensively and it is always reliable, then you can check how it is used in your sketch. You could, for example, dump everything to the Serial Monitor.
It seems that the use of Preferences is a little different when used with Arduino: https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/
the exact same preference code i had, was tested extensively before being incorporated into the project and it worked fine, I Will however take your advice and reduce the sketch and test it more thorougly.
the link you sent was the article i used as reference when writing my sketch. I will read it again and make sure that i did not miss anything
I have now reduced my sketch and it does still only save 42 rows and the rest are set to the preference default value that i have set to 12:
Does preference maybe have limit, but i have made my calculations and using int16_t then each element should take up 1byte of memory, me having 250 rows and 10 columns means i take up 2500 bytes and one partition should be 4096 bytes.
#include <Preferences.h>
int Test[250][10] = {0};
class FlashSave {
public:
FlashSave();
void saveRSSI(int RSSI[][10], int rp);
void loadRSSI(int RSSI[][10], const int numRows);
void clearRSSI(int RSSI[][10], const int numRows);
};
FlashSave flashSave;
FlashSave::FlashSave() {
// Constructor (if needed)
}
void FlashSave::saveRSSI(int RSSI[][10], int rp) {
Preferences preferences;
preferences.begin("RSSISave", false);
for (int j = 0; j < 10; ++j) {
String key = String(rp) + "_" + String(j);
int8_t value = RSSI[rp][j];
preferences.putChar(key.c_str(), value);
}
preferences.end();
}
void FlashSave::loadRSSI(int RSSI[][10], const int numRows) {
Preferences preferences;
preferences.begin("RSSISave", true);
for (int i = 0; i < numRows; ++i) {
for (int j = 0; j < 10; ++j) {
String key = String(i) + "_" + String(j);
RSSI[i][j] = preferences.getChar(key.c_str(), 12);
}
}
preferences.end();
}
void printMatrix(int RSSI[][10], int numRows) {
Serial.println("Matrix:");
Serial.println();
// Print matrix data
for (int i = 0; i < numRows; ++i) {
Serial.print(i);
Serial.print("\t"); // Print row number
for (int j = 0; j < 10; ++j) {
Serial.print(RSSI[i][j]);
Serial.print("\t");
}
Serial.println();
}
}
void FlashSave::clearRSSI(int RSSI[][10], int numRows) {
Preferences preferences;
preferences.begin("RSSISave", false);
// Clear preferences for the current namespace
/*
for(int i = 249; i < 500; ++i){
for(int j = 0; j < 10; ++j){
String key = String(i) + "_" + String(j);
preferences.remove(key.c_str());
}
}
*/
preferences.clear();
preferences.end();
}
void setup() {
Serial.begin(115200);
for(int i = 0; i < 250; ++i){
flashSave.saveRSSI(Test, i);
}
flashSave.loadRSSI(Test, 250);
printMatrix(Test, 250);
}
void loop() {
// put your main code here, to run repeatedly:
//Serial.print("hello world!");
}
I meant i am saving int8_t which is one byte.
You could add a test with
size_t whatsLeft = preferences.freeEntries();
But I think that it is hardware related. There has been a number of problems with the settings for Octal Flash and Octal PSRAM, QIO and PIO settings (I don't know what they are, but they keep coming when I search for troubles with the ESP32-S3): “Preferences.h” doesn't work on ESP32 S3 · Issue #8429 · espressif/arduino-esp32 · GitHub
Do you have another ESP32 variant ? Can you add a EEPROM to your project ?
Thanks, I will try that test. I do not think that it is hardware issues as, it worked before and i have tried with other esp32s and they all have the same problem. The esp32 does not support any EEPROM. But i will take a look at the github repo you sent and see if I gain something from it!
I moved your topic to a more appropriate forum category @chriskheder.
The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.
In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Thanks in advance for your cooperation.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.