I am currently working on a project where I use the filestream component of the Nextion Intelligent module.
I use it to write and read values that the Arduino Mega uses in its program.
My Issue is that I have a counter that shows on the Nextion the number of times that a button was pressed.
This value must be saved so that it is not lost when powering off.
But I fear that if I will rewrite the value of the counter on the MicroSD (where I am currently saving the Value of the counter) that the MicroSD won’t last very long since it has limited write cycles.
Does the Nextion always write the values to the same Bytes or does it change the Bytes where the file is saved (like on a PC) to extend the lifetime of the MicroSD?
If not, what would be a good solution to save these Values and not having to replace the MicroSD regularly.
Thanks a lot in advance and sorry if there are errors in my Post, since it is my first time posting.
I am also interested in this question
First off, I don’t think you’ll run into much of a write cycle issue (how many times can someone push a button?) but the Micro SD solution could have other failure points like corruption from power loss during a write procedure. Since this counter value is obviously important to your project, this could be a good opportunity to get creative and play around with some error correction/data backup schemes.
Here’s a thought - use the EEPROM on both the Arduino and Nextion as a backup storage location for your counter value. Both locations are non-volatile and easily accessible. With three storage locations available you are now able to both detect AND correct an invalid/corrupt counter (like a mini RAID configuration). For example, if the Arduino EEPROM and Nextion EEPROM both show a counter value of 500 but the Micro SD shows 4156123445 then your Micro SD value is obviously corrupted so signel the user to install a new Micro SD card then write a value of 500 to the replacement card. If the Micro SD returned a value of 499 then that might indicate that the power was lost (or the card was removed) during the last write cycle (in which case you prompt the user to check the power supply/connections and ensure that the card is fully inserted).
EEPROM also has write/erase cycle limitations (although it’s very high - see my prior post on EEPROM cycles) but it’s still a limitation none the less so an error correction scheme is always a good idea. Since the EEPROM on the Arduino and Nextion can’t be quickly swapped for replacement like a Micro SD card, you could instead store a flag at the corrupt memory location and move to a new storage address in the EEPROM. For example, if the Nextion EEPROM and Micro SD return a counter value of 500 but the Arduino counter, stored in EEPROM address 0, returns 42 then assume this EEPROM location is damaged and store the correct counter value of 500 to EEPROM address 1 in the Arduino. When checking EEPROM values, if you get an invalid counter value then know that it could be a previously used damaged location and to check the next address as well.
Hope this helps.