My idea is as follows.
- fix all components and wiring to XIAO with adhesive to reduce the effects of vibration.
- Connect a capacitor to a point 3V3 pin separate from the battery.
- Monitor the battery voltage and determine that a power failure has occurred if the voltage drops (e.g., below 3.4 V).
- When a power failure occurs, write the last data to Flash and do not write any more.
- A large capacitor (e.g., 1.5 F) supplies the energy required for the last write.
The following sample sketches will work.
xxxxx File–Examples–Examples for XIAO_MESP32C3–EEPROM xxxx
I have tried three libraries and recommend SPIFFS.
See the following link regarding battery voltage monitoring.
‘Battery voltage monitor and AD conversion for XIAO_ESP32C’