Is there a way to store variables in the Nano 33 BLE Sense so that it survives power down?
There's no EEprom.
I tried the FlashStorage library, but it's for the Samd mbed architecture and does not compile.
I'm also in need of a solution for this, specifically on the Nano 33 BLE. At the moment I can't find any compatible libraries or examples.
Apparently the SPI library works on flash memory
https://forum.arduino.cc/index.php?topic=668641.msg4594636#msg4594636
https://forum.arduino.cc/index.php?topic=324009.0
I did not try this one so far.
One other discussion
https://forum.arduino.cc/index.php?topic=676306.0
To be honest I don't understand the KVstore solution. I'm redirected to os.mbed.com/ but the example does not look like it's running on Arduino.
I managed to save persistent state on Nano 33 BLE using the FlashIAPBlockDevice.
I found an example where they initiate the device to the upper half the flash memory using parameters 0x80000, 0x80000. I worked nicely for me.
@traskdk: could you post an example sketch please? I'd love to use this lib, but only find references to mbed os. I need to use the Arduino ide though. Thanks
Check out this great GitHub repo -> GitHub - tjpetz/BLESenseFlash: Arduino sketch to write to Nano 33 BLE Sense memory using the NVMC
Can confirm it works on my Nano 33 BLE Sense, and it is well documented also.
It's also worth noting this is not the same as EEPROM emulation, as the Non-Volatile Memory Controller from Nordic is used at the hardware layer, and there is nothing to prevent this memory from being overwritten by the next flash of the device.
It is written in such a way that you define a const variable in code, then using the location of the variable, call operations which overwrite the page which contains the variable. The variable is sized to consume the whole page, and the page alignment is used to ensure that variable starts at the beginning of a page of memory.
Worth noting also that the total number of writes supported by Flash < 1,000,000 typically so rapid writing will reduce the lifetime of the device rapidly.
Flash writes need to operate without interruption.
NVMC use can lead to low level writes into unintended memory spaces, and therefore it is recommended that caution be exercised by the developer.