When using IDE 2.2.1, on Windows 10 or 11 with a Lolin ESP32-C3 Pico board, the IDE Serial Monitor will reset the board on every Serial connection. This is undesired if you are attempting to debug a sketch this uses deep sleep with a wakeup timer. When the board goes into deep sleep, the serial port disconnects because it is shut down by the ESP32. When the wakeup timer goes off, the sketch begins to execute and the serial port starts up again. When the serial port starts, however, the IDE Serial Monitor sends a USB reset to the board, so the board is restarted a second time. If you are using RTC_DATA_ATTR variables in the sketch, the USB reset causes the values in these variable to be lost. Thus the sketch does not operate properly after a wakeup.
There needs to be some way to tell the Serial Monitor to NOT send a USB reset.
I'm not "closing" the serial monitor. It goes inactive when the ESP32 C3 goes into deep sleep. It goes active again when the ESP32 comes out of deep sleep due to the timer going off and then the serial monitor resets the board.
I realize a different terminal program like putty might "solve" the problem, but it would be very nice to have an option in the IDE to allow this to work correctly.
HI @daledj. I think you are misinterpreting your observations. The sketch program restarting every time the board wakes from deep sleep is an inherent behavior of the ESP32 deep sleep.
This behavior has nothing to do with the Serial Monitor. You can verify that by connecting an LED to pin 2 on your board, closing Serial Monitor in Arduino IDE, then uploading this sketch to your board:
const byte LED_PIN = 2; // Connect an LED to this pin.
void setup() {
pinMode(LED_PIN, OUTPUT);
for (byte counter = 0; counter < 10; counter++) {
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);
}
esp_sleep_enable_timer_wakeup(5000000ULL);
esp_deep_sleep_start();
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}
You will see the LED pattern:
Blink quickly 10 times.
Stop blinking for 5 s
Repeat
If the Serial Monitor was the cause of the restart, we would instead expect the pattern:
Blink quickly 10 times.
Stop blinking for 5 s
Blink at 0.5 Hz forever
If you are unable to configure your sketch to work with the ESP32 deep sleep behavior, then you can use the "light sleep" instead, which behaves as you expect. Just replace the esp_deep_sleep_start call with esp_light_sleep_start:
Actually the behavior I observe does have to do with the USB Reset. What I observe is that the timer wakeup occurs as desired, then the serial port becomes active within 50 to 100 msec. Then the board is reset a second time, with the reset cause being USB_RESET. This is not related to deep or light sleep, but to the USB reset caused by the Serial port being restarted. If I close the serial monitor in the IDE, I do NOT get two resets, only one from the wake timer.
I need to use deep sleep because my device (which runs for about 3 months on a batter) goes to sleep for 15 to 20 minutes at a time, wakes for about 5 to 10 seconds, takes a measurement and reports to WiFi.
The Arduino boards platform framework does provide the ability to configure whether the control signals should be asserted when Serial Monitor is opened:
The configuration of the "LOLIN C3 Mini" board definition you are using is already configured to disable the Serial Monitor's behavior of asserting DTR and RTS when opened though:
These are traditionally only relevant for boards like the UNO R3 that use a dedicated USB chip, and not for the "native USB" boards like the Leonardo that are directly connected to the computer via the USB cable. The ESP32-C3 boards fall into that "native USB" category. However, it is possible the USB stack could be configured to reset a native USB chip if the signals are asserted. I found a report of that here:
I experimented with changing those values, like so:
However, regardless of which of the three configurations I use, when I run the File > Examples > ESP32 > DeepSleep > TimerWakeUp sketch on my ESP32-C3 board, I get the following:
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xe (SPI_FAST_FLASH_BOOT)
Saved PC:0x4200ebc0
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x438
load:0x403cc710,len:0x90c
load:0x403ce710,len:0x25f4
entry 0x403cc710
Boot number: 1
Wakeup was not caused by deep sleep: 0
Setup ESP32 to sleep for every 5 Seconds
Going to sleep now
Yes, I observe the same USB_UART_CHIP_RESET message about 50 to 100 msec after the timer wakeup. I think that the serial port on the ESP32 C3 is emulated by the windows driver and the code on the chip because there are only two data lines that connect from the USB interface to the chip, D+ and D- which go to GPIO19 and GPIO18. (Unlike an old serial port where DTR and RTS where real, physical connections.)
So I think this has something to do with the windows driver. I observe something else interesting: When the chip wakes up from deep sleep, the Arduino IDE observers this fact: In the lower right corner, it says "connected". If the Serial Monitor is not running, all works properly on the board and when it goes back to sleep again, the IDE reports "disconnected". So somehow the IDE can tell when the board is connected without forcing a USB reset, but when the Serial Monitor opens the port, the reset occurs. That is why I think in may be a windows driver issue, especially given your observation about DTR and RTS being disabled in the configuration. So, either a bug in the driver, or the way the IDE tries to tell the driver not to use DTR and RTS...