ESP32 Onboard LED Flash lighting up in Deep Sleep

Hi all, I'm currently learning to use the ESP32 Cam board and have been trying to implement a deep sleep state for it. Whenever it goes into deep sleep, the LED light (GPIO 4 Pin) will become dimly lit until the deep sleep timer resets. This defeats the purpose of using a deep sleep because the LED is likely to draw more power over-time. I'm unsure of what's the cause of this issue after Googling for the past hour. Would appreciate some suggestions on what I can do to fix this issue. Please refer to the image and code snip below!

Deep sleep function:


void goToDeepSleep() {
  Serial.println("Going to sleep...");
  digitalWrite(4, LOW);    // Extra measure to turn the light off before going to sleep

  // Deep sleep for x Minutes (LED starts to become dimly lit here)
  esp_sleep_enable_timer_wakeup(PHOTO_INTERVAL * 60 * 1000000);
  esp_deep_sleep_start();

}

you may need to set the GPIO state before/during deepsleep

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html

or set the pin to be an RTC pin, controllable by the ULP and set it low.

void esp_sleep_config_gpio_isolate(void)

void esp_sleep_enable_gpio_switch(bool enable)

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html

1 Like

Hi Idahowalker,
Thank you for the swift reply!
I've had a look at the resources you've provided but I'm still quite lost because I'm very new to Arduino and microcontrollers in general.
Would you mind going into more details about what you mean by setting the GPIO state, and the 2nd solution of setting an RTC pin?
Thanks again!

This is the right thing to do, but for some reason it is not working as expected.

digitalWrite(4, LOW);    // Extra measure to turn the light off before going to sleep

If you look at the schematic for the ESP32-CAM, the LED is driven by a transistor, via GPIO4, which has a 47K pullup. That suggests that GPIO4 is going into a high impedance state (e.g. INPUT) during sleep, and the pullup resistor is enough to weakly activate the LED.

As suggested above, investigate how the sleep modes handle I/O pins set to OUTPUT. There must be some way to force GPIO4 to remain OUTPUT and LOW during sleep. Start here: Sleep Modes - ESP32 - — ESP-IDF Programming Guide latest documentation

Note: "isolate" is not what you want. But this looks promising:

esp_sleep_enable_gpio_switch()
Enable or disable GPIO pins status switching between slept status and waked status.

Schematic:

1 Like

Hi jrmington,
Thank you for providing the schematic and talking about the GPIO04!
My solution was to input this line of code right before the sleep function and it worked flawlessly!

Appreciate the kind assistance!

rtc_gpio_isolate(GPIO_NUM_4);

Final code:

void goToDeepSleep() {
  Serial.println("Going to sleep...");
  digitalWrite(4, LOW);    // Extra measure to turn the light off before going to sleep
  rtc_gpio_isolate(GPIO_NUM_4); // <<<<<<<<<<< Added code

  // Deep sleep for x Minutes (LED starts to become dimly lit here)
  esp_sleep_enable_timer_wakeup(PHOTO_INTERVAL * 60 * 1000000);
  esp_deep_sleep_start();

}
1 Like

Good to know.

Evidently the "enable hold" operation of rtc_gpio_isolate() is the key:

Helper function to disconnect internal circuits from an RTC IO This function disables input, output, pullup, pulldown, and enables hold feature for an RTC IO.

gpio_deep_sleep_hold_en should work as well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.