Arduino/esp32 many and high frequently saving to memory

Hello everyone,

I am a bit stuck with how i want to proceed further, I'm writing my own stepper motor program/library and I have never worked with memory accessing with a MCU.
Now I'm at the point that i want to save the real world position of what the stepper is controlling.

The data I want to store is of format double/Float (position of the motor in degrees) but could be 2-32 bit integers if that would be better, not sure yet, later on i want to be able to store wifi login data aswell, this should still be an option.

I want the stepper to be able to run both with and without an ethernet connection so saving the position online is not sufficient.

I need the memory to be Non volatile, it should retain its stored data after a power fail.

the rate at wich the stepper takes its steps can range from mere microseconds(not with the arduino) to hundreds of miliseconds.
I was thinking to save its position after every several degrees of movement, so when the motor is running fast, the amount of position updates saved to the memory will rack up very fast, therefor the EEPROM memory is not really a reliable choice. Also EEPROM is not an option for the esp32 as it does'nt have this.

I want my library to be compatible with both esp & arduino boards even tough the latter is not really a great choice for it.

So with the ESP32, what type of memory is to be recommended that retains its reliability over years to come with so many high frequent saves to it?
and what for the arduino boards? can it be done without using a third party module/shield.

Add a FRAM.

2 Likes

Looking into that now but i already see a problem:
Fram is over I2C or SPI, in SPI, how fast does a write or read operation take? is it in the scope of 1,10,100,1000's of microseconds?
[EDIT]=> this answered that question.

I need to be able to store the data as fast as possible as to not delay the program continuation to much, the total time it takes the program to run once is the limiter to the speed of the motor and with arduino boards that is already a pretty high number.

I think the only reliable solution will be a battery/superercap backup with power fail detection. When main power is lost, the battery power is used to save the position to EEPROM.

3 Likes

I feel rediculous for asking but i need to ask it ..
In arduino IDE, how do i include the nvs_flash library? i can't seem to find it in the library manager, I have installed the ESP32 boards and updated the additional boards url in the preferences section.
I can see alot of esp32 related examples and such but i can't find the original nvs_flash library to be able to use flash memory as non volatile memory in the way documented in the API reference page. Also, when using the nvs library, is wear leveling, encryption and other more advanced "add-ons" automaticly applied?

@pollyscracker look at the Preferences library

https://docs.espressif.com/projects/arduino-esp32/en/latest/tutorials/preferences.html

In arduino IDE, when i search for library preferences i find only this one: GitHub - vshymanskyy/Preferences: Preferences library for Arduino, ESP8266, RP2040 and Particle. ESP32-compatible API

this is not the same one as the preferences developped by espressif, how can i know i am installing the right preferences from ESP and how do these 2 not conflict with each other if both are installed?
is the esp preferences automaticly installed when installing the esp boards and documentation and where is it located, where can i check the .cpp and .h files on my computer? (i know i can see them online but i'm asking if these are also present on my pc once esp boards and documentation is installed.

Will the esp preferences also work with arduino boards to store data in its eeprom memory?

@pollyscracker when you add ESP32 to the Arduino IDE certain libraries are also included. "Sketch->Include Library->Preferences" this menu item should allow you to include the Preferences library and is the only one you need.

In the previous link I provided those docs. have a "Real World Example" that demonstrates storing a key / value pair to NVS using the above library.

Edit: this is for esp nvs and not eeprom

1 Like

Thanks, i noticed these only show up when i select and esp board, otherwise they don't show. that was my problem, also i find it a bit confusing that i can't find all these libraries in my installed folder, i did saw however they are somewhere in the appdata folder but havent checked yet to see if the full cp and h file are in there but i figured i'd just use the online documentation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.