Page 1 of 1

Why use Serial.println() to configure sleep mode?

Posted: Mon Oct 14, 2019 3:35 am
by Involute
I'm developing some code that I want to put into deep sleep. According to what I've read, the configuration instruction should be as follows:

Code: Select all

Serial.println(esp_deep_sleep_enable_ext0_wakeup((gpio_num_t)RTC_IN, 0));   // 1 = active high, 0 = active low.
In my application RTC_IN is the pin through which I feed a signal from an external RTC which I'll use to awaken the ESP32.

My code compiles, though I haven't tried to run it yet. Why is the configuration instruction supposed to be placed inside a Serial.println() statement? Especially since the command to go to sleep is not placed in a Serial.println(), as expected:

Code: Select all

esp_deep_sleep_start();
Why not just use:

Code: Select all

esp_deep_sleep_enable_ext0_wakeup((gpio_num_t)RTC_IN, 0);   // 1 = active high, 0 = active low.
Which also compiles, btw.

Also, which pins can be used to trigger the wake-up? Thanks for any tips?

Re: Why use Serial.println() to configure sleep mode?

Posted: Mon Oct 14, 2019 5:51 am
by boarchuz
Its just passing the return value to println() for debugging. Same as

Code: Select all

esp_err_t result;
result = esp_deep_sleep_enable_ext0_wakeup((gpio_num_t)RTC_IN, 0)
Serial.println(result);
You can see the return values here:
https://docs.espressif.com/projects/esp ... pio_num_ti
So if you see anything other than "0" (ie. ESP_OK) then something has gone wrong. If you don't want to see this, you can remove the println() as you noted.
It also happens to list all the RTC pins there so you know which you can use.

Re: Why use Serial.println() to configure sleep mode?

Posted: Mon Oct 14, 2019 5:55 am
by Involute
Ah, got it. Thanks.