Skip to main content

Posts

Showing posts with the label Arduino Framework

ESP32 Deep Sleep Secrets: Persisting Data with RTC_DATA_ATTR and RTC Memory

  You have designed a low-power sensor node. It wakes up, reads a sensor, and enters Deep Sleep to conserve battery. Ideally, you want to batch these readings and transmit them only once every ten wake cycles to save radio power. However, every time your ESP32 wakes up, your variables reset. Your batch buffer is empty, and your counters are back to zero. The immediate reaction is often to write state to the NVS (Non-Volatile Storage) flash or an SD card. This is a mistake for high-frequency data. Flash memory has limited write cycles (wear leveling becomes an issue), and SD cards consume significant power during initialization. For transient state maintenance across sleep cycles, the ESP32 offers a dedicated hardware solution:  RTC Memory . The Architecture of Amnesia (The Root Cause) To fix the problem, you must understand the ESP32's power domains. The ESP32 is not a single block of memory. SRAM (Static RAM):  This is where your standard global variables, stack, and hea...