Page 1 of 1

ESP32 wroom, Flash Memory preferences.h

Posted: Mon Sep 04, 2017 5:03 am
by rodmcm
Being a simple soul all I want to do is use wroom flash like I use EEPROM. Can someone please provide a toddlers guide to ESP32flash in the arduino environment. I have looked at preferences.h and the two examples provided but they are for single entities, a counter and a string, not a set of data, the '"blob" example link does not operate.

My limited understanding from these examples is that you define a partition under begin() and that each memory location is essentially "pointed at" by a const char descriptor rather than an memory location as would be the case with an EEprom

So I used the following to assign a large amount of variables and read them back

To Write..................
#include <Preferences.h>
Preferences preferences;
void setup() {
Serial.begin(115200);
preferences.clear();
preferences.begin("my-app", false);

for (int i=0;i<1000;i++)
{
String loc=String(i);
preferences.putUInt(loc.c_str(),i);
}
// Close the Preferences
preferences.end();

}

void loop() {}

I shut the power to the wroom, repowered and then downloaded the read program...

#include <Preferences.h>
Preferences preferences;
void setup() {
Serial.begin(115200);
preferences.begin("my-app", false);

for (int i=0;i<1000;i++)
{
String loc = String(i);
unsigned int j=preferences.getUInt(loc.c_str(),0);
Serial.print(j);
Serial.print(" ");
}
preferences.end();
}

void loop() {}

This read back 0,1,2,3,4.... to 365 and then a series of 0's for the rest of the readback for the remaining 635 reads!!!!

I then changed the write to
preferences.putUInt(loc.c_str(),2*i); // double the value in each location

and nothing changed... the new values did not seem to go in . the same answer came back

So, a simple understanding please...

Also there is an EEprom example provided that I cannot get to work, also it says that it is only good for 4.2kB... Why?

Re: ESP32 wroom, Flash Memory preferences.h

Posted: Thu Sep 07, 2017 3:33 pm
by tele_player
I suspect you hit a size limit writing to NVS. You should check the return value of each call to putUInt. 4 is good, 0 is error.