• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Save string or array in RTC memory in ESP32 deep sleep

Q&A Forum › Category: ESP32 › Save string or array in RTC memory in ESP32 deep sleep
0 Vote Up Vote Down
Steven Falivene asked 6 years ago

Hi,

I have managed to save the boot count (two of them) after a deep sleep on the ESP 32, but I can not save a string and add to the string on each boot.

How can I save a string? My final aim is to read an analog pin on each wakeup, then after 20 wakeups get the max, min, average and median of the 20 readings.

If there is an way to store an array, then please teach me, however out of curiosity I still like to store a string. I am a beginner.

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 3 /* Time ESP32 will go to sleep (in seconds) */
#define LED 2
RTC_DATA_ATTR int bootCount = 0;
RTC_DATA_ATTR int bootCount2 = 0;
//int bootCount = 0;
//int bootCount2 = 0;
RTC_DATA_ATTR String RTCvariable = "H";
void setup(){
Serial.begin(115200);
delay(500);
Serial.println("ESP32 boot RTC test");
if(bootCount == 0) //Run this only the first time
{
//digitalWrite(YELLOW_LED_PIN,HIGH);
delay(500);
//Increment boot number and print it every reboot
Serial.println("Boot count = 0 , first time boot ");
Serial.println("Boot count2 = 0 , first time boot ");
}else // not first boot
{
Serial.println("2nd + boot. Boot number: " + String(bootCount));
Serial.println("2nd + boot2. Boot number: " + String(bootCount2));
}
Serial.println("RTCvariable: " + String(RTCvariable));
++bootCount;
++bootCount2;
//RTCvariable.concat("A");
//RTCvariable += "A";
RTCvariable += 'A';
Serial.println("Enter deep sleep for 3 seconds");
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
void loop(){

}
Question Tags: ESP32 RTC string
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Steven.

Unfortunately, I don’t have a clear answer for you. I don’t know how to store arrays or strings in the RTC memory.

There is a library that does exactly what you want, but it was built for the ESP8266. https://github.com/highno/rtcvars
I think they will add support ESP32 in the future.

At the moment, I think the best option would be storing the temperature values in a position of the flash memory and then compare the temperatures in each position.

You should also need to keep track of the boot count so that you know where yo save each temperature.

You can see our tutorial about storing data on the flash memory here: https://randomnerdtutorials.com/esp32-flash-memory/

I hope this helps.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.