ESP32 deep sleep debounce

Verbatim12
Posts: 1
Joined: Tue May 06, 2025 8:14 pm

ESP32 deep sleep debounce

Postby Verbatim12 » Tue May 06, 2025 8:20 pm

I've been working on using an ESP32 board as a data logger for recording temperatures. I am trying my best to minimize power usage as I will be using a small battery to supply the microcontroller. I've been using an external RTC RV 8803 to set the interval between readings. I would like the ESP to wake up upon receiving a square wave signal from the RTC, collect any sensor data that I choose, then go back to deep sleep and wait for the next signal from the RTC. I'd like to be able to add or remove sensors and still maintain even spacing between readings without knowing exactly how long it takes. My current issue is that I can't find an easy way to debounce the signal from the RTC square wave. The controller ends up waking from deep sleep multiple times and recording before the square wave changes state. My question: Is there an easy way to wake up only once on the rising edge of the square wave from the external RTC? The esspressif documentation seems to imply that the wakeup pin will respond to either a high or low state and does not provide any option for rising edge detection. Thanks in advance.
image (1).png
image (1).png (9.43 KiB) Viewed 143 times
image (2).png
image (2).png (51.47 KiB) Viewed 143 times

Code: Select all

#include <Wire.h>            // Used to establish serial communication on the I2C bus
#include <SparkFun_TMP117.h> // Used to send and recieve specific information from our sensor

// The default address of the device is 0x48 = (GND)
TMP117 sensor; // Initalize sensor

#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex


int TIME_TO_SLEEP = 5;                        // Time ESP32 will go to sleep (in seconds)

unsigned long long uS_TO_S_FACTOR = 1000000;  // Conversion factor for microseconds to seconds

RTC_DATA_ATTR int bootCount = 0;              // Number of reboots


void setup() {

  /****  Do your stuff here! ****/

  Serial.begin(115200);                                 // Start serial communication at 115200 baud rate
  Wire.begin();
  Wire.setClock(400000);   // Set clock speed to be the fastest for better communication (fast mode)

  sensor.begin();

  ++bootCount;                                          // Add 1 to the current value of bootCount

  Serial.println("Boot number: " + String(bootCount));  // print the value of bootCount on the serial monitor

     if (sensor.dataReady() == true) // Function to make sure that there is data ready to be printed, only prints temperature values when data is ready
  {
    float tempC = sensor.readTempC();
    float tempF = sensor.readTempF();
    // Print temperature in °C and °F
    Serial.println(); // Create a white space for easier viewing
    Serial.print("Temperature in Celsius: ");
    Serial.println(tempC);
    Serial.print("Temperature in Fahrenheit: ");
    Serial.println(tempF);
   }

  Serial.println("Going to sleep now");                 // Print when the ESP is about to go into deep sleep mode

  /* Now we wrap up for Deep Sleep - I hope you did everything you needed to... */

  //esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);  // Set up timer as the wake up source and set sleep duration to 5 seconds
  //esp_sleep_enable_timer_wakeup(750000);


  esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,HIGH);


  Serial.flush();                                                 // Waits for the transmission of outgoing serial data to complete.

  esp_deep_sleep_start();                                         // Start the deep sleep mode

}

void loop() {

  // This is not going to be called

}

Who is online

Users browsing this forum: No registered users and 5 guests