Comments on: ESP32 Save Data Permanently using Preferences Library https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Sun, 26 Apr 2026 22:04:18 +0000 hourly 1 https://wordpress.org/?v=6.8.5 By: bill https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-1182322 Sun, 26 Apr 2026 22:04:18 +0000 https://randomnerdtutorials.com/?p=102041#comment-1182322 In reply to tobias.

Hi Tobias, I found that if using this example, yes it will write the data every time. Which is pointless as the details are hard coded anyway.

It is only a basic example, to give an idea. using EEPROM is easier, but it only holds one byte. The preference library allows 32 bit numbers, stings etc. so once one gets used to it, it is far more versatile.

The preferences library is clever, it checks the contents of the preference, to see if it matches that of the new data and only performs a write if it is different, so behind the preferences put, is something like….

if new input is different to new input then preferences.put

so in actual fact, repeatedly using preferences.put will only actually write if the new and old data is different.

preferences also uses memory wear levelling, unlike EEPROM which reuses the same memory location, preferences moves it about

I used a library (sorry cannot think of the name right now) that solves wifi issues.
On power up, it turns on the wifi as an access point.
One connects to the esp32 with your phone and input your wifi credentials.
It then reboots and connects to your wifi.

My code is on instructables. You may want to see how I use preferences and the libray to input the wifi details.
https://www.instructables.com/Triaxial-Numechron-Clock-Updated-Accurate-Electron/

]]>
By: tobias https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-1181448 Thu, 23 Apr 2026 21:02:15 +0000 https://randomnerdtutorials.com/?p=102041#comment-1181448 is it correct that the eeprom is written in the example at every startup? cause we have a limited amount of writing cycles.

would it be better to read first compare and then write?

]]>
By: bill https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-1175361 Fri, 03 Apr 2026 17:09:07 +0000 https://randomnerdtutorials.com/?p=102041#comment-1175361 How can one save a custom box, that then does not get overwritten when the esp32 is turned off & on?

It seems wifi manger checks the ssid & password and connects if it can, but rather than quitting there and returning, continues to read the text box (so is the default value).

So if one saves the value to preferences first time round, it just gets overwritten.

]]>
By: Stefano https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-1015810 Wed, 12 Mar 2025 08:40:41 +0000 https://randomnerdtutorials.com/?p=102041#comment-1015810 Great tutorial: really easier and faster than SPIFF that I used in past… many thanks!!

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-989206 Fri, 06 Dec 2024 10:28:03 +0000 https://randomnerdtutorials.com/?p=102041#comment-989206 In reply to Uwe.

Hi.
Thanks for noticing.
It’s fixed now.
Regards,
Sara

]]>
By: Uwe https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-988789 Wed, 04 Dec 2024 20:38:40 +0000 https://randomnerdtutorials.com/?p=102041#comment-988789 Hi,
thanks for this very useful help.
There is a small typo:
gettULong64 instead of getULong64 in the “Get a Key Value (Read Value)” section.
Br
Uwe

]]>
By: Patrick https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-972129 Tue, 15 Oct 2024 08:12:15 +0000 https://randomnerdtutorials.com/?p=102041#comment-972129 I would like to ask how much read/write cycle is ESP is capable of?

Because i am planning to make a product counter with ESP

daily count: 1800 pcs

trigger :1 million pcs

My concer is how to ensure the data is preserved

Thanks

]]>
By: Xylopyrographer https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-917718 Fri, 24 May 2024 05:35:30 +0000 https://randomnerdtutorials.com/?p=102041#comment-917718 In reply to Allen Mulvey.

Preferences uses a portion of the on-board flash as its namespace. Thus when the flash is erased, so is the space used by the Preferences library. This is how it has always been.

For more detail, see the Resources section at the end of the Preferences Tutorial on the arduino-esp32 GitHub site at: https://docs.espressif.com/projects/arduino-esp32/en/latest/tutorials/preferences.html

]]>
By: Allen Mulvey https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-916834 Mon, 20 May 2024 23:49:21 +0000 https://randomnerdtutorials.com/?p=102041#comment-916834 This article is a little old and these things change fast. Using the Arduino IDE and setting “Erase all flash before sketch upload” to enabled now (May 2024) deletes the preferences.

Thanks again for all your work.

]]>
By: jorge medina https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/#comment-886800 Mon, 29 Jan 2024 10:29:27 +0000 https://randomnerdtutorials.com/?p=102041#comment-886800 Antes que nada gracias por todos sus aportes, siempre son el impulso suficiente para desarrollar proyectos con cada nueva tecnología que ocupo, asi que de nuevo muchas gracias!! Hoy recurro a ustedes para obtener ayuda respecto a la compilación de la biblioteca en VisualStudioCode, ya que no encuentro solución en ningún sitio. El problema es que al compilar aparece el error “For ESP32 devices, please use the native Preferences library”. Este error se presenta con la versión de biblioteca 2.1.0 y 2.0.0, las dos únicas versiones de esta. Tambien probé cambiar la version de framework, desde la 6.5 hasta la 4.4, y da el error con todas las combinaciones entre versiones de framework y biblioteca.

]]>