The specs for both ESP32 and ESP8266 talk about RTC memory for data retention between deep sleep instances. This is useful for counts, previous sensor values etc.
I have found many useful articles on exploiting this with Arduino C code but I have found nothing to tell me how to do this with MicroPython. Am I bad searcher or does it not exist?
I have read of using flash memory but flash memory is reputed to have limited write cycles. Or am I wrong on this too?
Thanks in advance for any help on this.
Persistent data with deepsleep
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Persistent data with deepsleep
Flash memory does have a limitation on the number of write cycles, typically on the order of 10,000.
The following works on an ESP8266:
The following works on an ESP8266:
Code: Select all
import machine
import ujson
rtc = machine.RTC()
d = {1:'one', 2:'two'} # Example data to save
rtc.memory(ujson.dumps(d)) # Save in RTC RAM
r = ujson.loads(rtc.memory()) # Restore from RTC RAM
# r == {2: 'two', 1: 'one'}
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Persistent data with deepsleep
Hi Peter
I think the memory in RTC is static ram (however i have not digged into the datasheet), but I decided to sacrifice one of my ESP’s (TTGO T7 Mini) for a test.
Every 5 ms I write a consecutively and a random number to the RTC, then I read them back and compare the value.
So far it has performed 3.162.000 W/R and still counting
Mvh Otto
I think the memory in RTC is static ram (however i have not digged into the datasheet), but I decided to sacrifice one of my ESP’s (TTGO T7 Mini) for a test.
Every 5 ms I write a consecutively and a random number to the RTC, then I read them back and compare the value.
So far it has performed 3.162.000 W/R and still counting
Mvh Otto
Re: Persistent data with deepsleep
You might find parts of https://github.com/karfas/upy-esp32-lib useful.
Besides that, two of my pull requests hopefully increase the usability of RTC memory:
https://github.com/micropython/micropython/pull/7298
https://github.com/micropython/micropython/pull/7133
Besides that, two of my pull requests hopefully increase the usability of RTC memory:
https://github.com/micropython/micropython/pull/7298
https://github.com/micropython/micropython/pull/7133
A few hours of debugging might save you from minutes of reading the documentation!
My repositories: https://github.com/karfas
My repositories: https://github.com/karfas