Hey all,
I want to explore the sleep modes on ESP32 using Arduino IDE. By referring the ESP8266 guide, I am able to put the ESP32 in deepSleep mode.
I want to use my ESP32 in either lightSleep or modemSleep, both of which are not defined in #include "esp_deep_sleep.h" nor they have separate header files in espressif\esp32\tools\sdk\include\esp32.
Is there a way to use the other sleep modes or they are yet to be explored?
I have implemented the sleep modes in the basic Blink program for which the code is attached.
Thank you!
#include "esp_deep_sleep.h"
int ledPin = 5;
// Time to sleep (in seconds):
const int sleepTimes = 15;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
}
void loop()
{
Serial.println("Hello, world!");
digitalWrite(ledPin, HIGH);
delay(1500);
digitalWrite(ledPin, LOW);
delay(1000);
Serial.println("Please wait...");
Serial.println("Entering deep sleep mode...");
// deepSleep time is defined in microseconds. Multiply
ESP.deepSleep(sleepTimes * 1000000);
}
Quote from ESP_igrr https://www.esp32.com/viewtopic.php?f=19&t=716#p3110
Light sleep is essentially suspending the CPU, this is supported in the ESP-IDF (and happens automatically), but due to Arduino "loop" which runs constantly, this doesn't work in Arduino. This will probably also be supported somehow, but i'm not sure what the API should be. Modem sleep is already supported and enabled by default, unless SoftAP mode is used. There is no API to disable it, but unlike the ESP8266, enabling modem sleep doesn't mess with LwIP timers, so there should be no problem with keeping it enabled.
Thanks, that was helpful!
So, I assume I can't use lightSleep in Arduino IDE for now.
Is is possible to use Watchdog Timers in ESP32 to go in sleep mode? Is there any example available for reference?
Thanks!
Yes.
#include <Arduino.h>
void setup() {
Serial.begin(115200);
Serial.println("This will be printed every 5 seconds");
esp_deep_sleep_enable_timer_wakeup(5000000);
esp_deep_sleep_start();
}
void loop() {
// This will never be reached
}
@architmuchhal12 Is this question answered for you? If yes,we will retain it for reference.
Even if he's happy with deep sleep, you might want to keep this issue around because light sleep doesn't work yet?
FWIW, I don't buy the argument that it doesn't work because of Arduino's loop, because on ESP8266 it works as long as you're executing delay(t) with t > 0.
There it is:
#include <WiFi.h>
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("light_sleep_enter");
esp_sleep_enable_timer_wakeup(10000000); //10 seconds
int ret = esp_light_sleep_start();
Serial.printf("light_sleep: %d\n", ret);
}
At least the current consumption goes down for me when using delay. Seems to be ok
Here is some documentation and tests about it: https://github.com/espressif/esp-iot-solution/blob/master/documents/DFS_and_light_sleep/light_sleep_performance_en.md
Will close due it was implemented
In Arduino IDE there's no CPU frequency to set(only "Flash frequency"). By default the frequency is 240MHz. You can however change via:
#include <soc/rtc.h>
void setup() {
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M);
}
The power consumption decrease half or more instantly! And to test if the rtc_clk_cpu_freq_set() works, you can do this:
int usCount = 0;
int lastUs = 0;
void loop() {
if (micros() - lastUs > 1000000) {
Serial.println(usCount);
usCount = 0;
lastUs = micros();
}
usCount++;
}
The usCount will be different between utilize or not utilize rtc_clk_cpu_freq_set(). You can do Serial.print(usCount) but will affect precision however.
In this section of ESP32 documentation you can find a way to put it into the light sleep mode.
Most helpful comment
Yes.