Page 1 of 1

Persistent data with deepsleep

Posted: Sat Nov 16, 2019 8:01 pm
by CharlesG
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.

Re: Persistent data with deepsleep

Posted: Sun Nov 17, 2019 9:03 am
by pythoncoder
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:

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'}

Re: Persistent data with deepsleep

Posted: Wed Nov 09, 2022 2:02 pm
by OttoMan28
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

Re: Persistent data with deepsleep

Posted: Sun Nov 13, 2022 3:39 pm
by karfas
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