Saving data when Power is lost

I’m trying to get data to be saved on my Micro:Bit that remains there when power is lost but I can’t find how. I’ve tried Aria (Opera’s build in AI based on ChatGPT) but no correct response. Is it possible as Micro Python can.

Hi,

Following another forum member’s request (@mwest226 's request here: Pull CPP files (Online makecode.microbit.org) - #4 by bsiever), I did create an extension with blocks that can be used to save and restore text from flash: https://github.com/bsiever/microbit-pxt-flashstorage .

Here’s an example using it: https://makecode.microbit.org/S34893-47565-25042-23479 (I just put this example together and haven’t tested it on a micro:bit yet).

Bill

1 Like

Ive tried it on my Microbit V2.00 and when pressing A the number goes up by 1 an and removing then inserting power it displays the last saved number as the code instructs. Thanks for the help!

1 Like

I’m testing the limits of the @bsiever 's extension on the microbit and I cannot get my microbit to store more than 5 pairs. I believe I should be able to store 21 pairs (key limited to 16 bytes and data limited 32 bytes). I wonder if it is my code that is the problem. Have you been able to store more pairs. Thank you

Hmmm…Looks like there’s an intentional limit of 5 pairs on the micro:bit v2 (but not on the v1). See: Defined Limit and Where it’s used. Weird — may want to open an issue about it. It might be wasting most of a block of flash (but there may have also been some reason for that choice).

Possible alternatives:

  • It may be possible to write something that directly interacts with the flash rather than using the KeyValueStorage.
  • It may also be possible to write something that interacts with the space used for the Data Logging blocks

Both of those would require a C++ based extension.