Xiao ESP32-C3 saving data

I am working on a project where I want to save data from an accelerometer to the xiao. I have done some looking around and seen that the flash storage can’t really be written to very many times (I keep seeing 10,000 or 100,000 write cycles). Is that the 4mb of onboard flash in the spec sheet that has that limit or is it some other storage type on the board? My hope was that I would be able to write data from the sensor every 0.5 seconds or so for the length of a test (probably around 40 seconds) and then to clear that data to start a new test. Is that going to be possible or will I just brick the storage pretty quickly?

Hi there,
How much Data? There are some tricks they use to spread that out over decades, You don’t write or erase the whole thing each time. It’s a combination of moving and copying pages also.
there is a good post I saw how if done properly can last for years.
I would start by calculating HOW much each write cycle, Check out Msfujino’s posts on storing data to flash , then writing to SD card and I think streaming it over the BLE link also.
HTH
GL :slight_smile: PJ :v:

Thanks for responding. I am not entirely sure how much data there is per cycle. I said just an accelerometer but there is actually a couple more sensors. I would estimate that I want to store ten different values which probably would all be floats every write cycle.

Can you link that post that you are referring to?

Hi there,
Sure I think it’s this one , but the Guy’s a Ninja :ninja: so many good ones. :wink: :+1:
HTH
GL :slight_smile: PJ
Also you can add it to the “Grove expansion Base” With More flash installed, check the Demo’s :v:

Hi alec,
Storing 10 sensor data (floating point: 4 bytes) at 0.5 second intervals for 40 seconds would require about 3.2 kbytes. 10data * 4bytes * 40sec / 0.5sec=3200bytes
If RAM space is available, it would be easier to use RAM.

I am not familiar with writing to RAM. I was under the impression that this would clear if power is lost which wouldn’t work for my application. Is that correct?

We may be able to help with more specific information, such as hardware configuration.

Experimentally, you can easily store the data on an SD card using the XIAOExpansionBoard with a battery connected.

Hardware configuration is pretty simple. I have the single xiao board connected to a wt901b MPU sensor and all of it is powered by a small battery. The whole package has to be as small and light as possible since it will be launched/thrown (it is being used for analyzing motion of rockets and other projectiles).

I was hoping that I could store all of the data on the board and then just plug it into a computer to pull data off after each test. I was hoping that the data would stay on the device just in case the power cuts out which could be possible if it lands poorly and connections come loose.

Assume that 4 kbytes of data is written to flash for one flight and that 1 MB of space is used. If the address to be written each time is changed, 250 times of flying data can be written. If we assume that the write life of Flash is 10000 times, 2500000 times of flying data can be written. I think the lifetime of flash is sufficient, but what do you think?

If power is lost while writing, data may be lost. An interrupt must be generated by a power failure to ensure that the writing process is completed. You may need to install a high-capacity capacitor (such as a super capacitor) at 3.3V as an energy source during this time.
Is there much to process during flight other than recording data?

Okay yeah putting it that way makes it seem like not an issue. I have done some more looking into storing the data and I came across the EEPROM library and SPIFFS library. For context, I have never done this before so I am very uninformed right now. When I was looking at the SPIFFS library I saw a comment that says there is no limit to write cycles when using it. I think I am a bit confused about all the ways data can be stored on this microcontroller. The official datasheet says that there is 4MB of flash storage. I was assuming that the EEPROM library uses that but is that incorrect and instead that is what SPIFFS library uses? I also came across the PREFERENCES library which I assumed writes data to somewhere else on the microcontroller. Does any of that make sense or am I completely ignorant here? I’m assuming the latter.

As for the capacitor option, I like the idea. Although I am already going to be connected to a battery so I am assuming that if the battery disconnects, a capacitor would probably run into the same issue. But no there is pretty little to process. My plan is to have a switch that “primes” the recording by holding the prior couple seconds of data in RAM then start recording when the accelerometer detects a high enough acceleration (the data in RAM would then be added to the start of the recording so I don’t miss anything). Then I guess in flight it would only process whatever is needed to store values and check for motion to stop so that I can automatically stop recording. My plan was to do any formatting of the data after the fact.

My idea is as follows.

  1. fix all components and wiring to XIAO with adhesive to reduce the effects of vibration.
  2. Connect a capacitor to a point 3V3 pin separate from the battery.
  3. Monitor the battery voltage and determine that a power failure has occurred if the voltage drops (e.g., below 3.4 V).
  4. When a power failure occurs, write the last data to Flash and do not write any more.
  5. 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

1 Like