Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

A quick example of nvm usage?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

A quick example of nvm usage?

by chjade84 on Sat May 02, 2020 3:27 pm

I've spent the last hours trying to figure out how to save variables between power cycles and finally discovered the nvm module. My M0 basic I'm using at the moment for developing doesn't support it but I have a nRF52840 Express in the mail that does, so I'll wait for that to arrive.

As someone new to Python and CircuitPython (and coding in general), is there a simple guide on how to use it effectively? It looks like it uses a bytearray which presumably is an array; something that's always confused me a little bit. I'm just looking to store my user-set variables in the event of a power loss.

Thanks!

chjade84
 
Posts: 5
Joined: Mon Apr 27, 2020 2:38 pm

Re: A quick example of nvm usage?

by danhalbert on Sat May 02, 2020 9:43 pm

Yes, it's just a byte array, so if you're just storing byte-sized values or booleans or similar, you can write them directly. Otherwise check out the `struct` module (same as in regular Python), which lets you pack and unpack values into byte strings: https://docs.python.org/3/library/struct.html

danhalbert
 
Posts: 2037
Joined: Tue Aug 08, 2017 12:37 pm

Re: A quick example of nvm usage?

by chjade84 on Sun May 03, 2020 12:29 pm

I will take a look, thanks! I vaguely remember struct from C++ back in my college days; wonder if that will be helpful in understanding at all, lol.

chjade84
 
Posts: 5
Joined: Mon Apr 27, 2020 2:38 pm

Please be positive and constructive with your questions and comments.