Persistent data with deepsleep

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
CharlesG
Posts: 1
Joined: Sat Nov 16, 2019 7:49 pm

Persistent data with deepsleep

Post by CharlesG » Sat Nov 16, 2019 8:01 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Persistent data with deepsleep

Post by pythoncoder » Sun Nov 17, 2019 9:03 am

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'}
Peter Hinch
Index to my micropython libraries.

OttoMan28
Posts: 3
Joined: Tue Aug 28, 2018 11:06 pm

Re: Persistent data with deepsleep

Post by OttoMan28 » Wed Nov 09, 2022 2:02 pm

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

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Persistent data with deepsleep

Post by karfas » Sun Nov 13, 2022 3:39 pm

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
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Post Reply