Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) ESP32 deep sleep fails when serial monitor is open (Read 3082 times)
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
ESP32 deep sleep fails when serial monitor is open
Jun 26th, 2023 at 4:49pm
Print Post  
The program compiles on BOTH VMicto and Ardiono IDE.
When run on Target the Arduino Compiled program works as expected, when the VMicro compiled program is run it does NOT give expected result.
It Resets when waking from Deep Sleep instead of Waking (correctly) from Deep Sleep. The Text output iss as below: On the Arduino version it increments the BootNumber counter and the wakeup_reason = esp_sleep_get_wakeup_cause(); works correctly.

Port open
Hello
Boot number: 1
Wakeup was not caused by deep sleep: 0
Setup ESP32 to sleep for every 10 Seconds
Port open
Hello
Boot number: 1
Wakeup was not caused by deep sleep: 0
Setup ESP32 to sleep for every 10 Seconds
Port open

« Last Edit: Jun 29th, 2023 at 11:04am by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #1 - Jun 26th, 2023 at 6:27pm
Print Post  
Thanks for all the information. Can you click Build>Clean Solution, then build and provide the output again.

Also see if that resolves?

If it doesn't resolve then please open arduino ide for same code, click File>Preferences>Verbose 
Compile. Than post that output
  
Back to top
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #2 - Jun 27th, 2023 at 2:05pm
Print Post  
Quote:
Can you click Build>Clean Solution, then build and provide the output again.

That did not solve the problem, but the problem has changed. Using the VisualMicro compiled code I can get the correct output on the Aruino IDE. With the Arduino IDE open, every time the ESP32C3 wakes up, the serial port re-appears and clicking on the Arduino Serial Monitor puts up the output from the ESP (Only the latest page) with an incrementing BootCount and the correct wakeUpReason.
On the VMicro application the SerialMonitor is visible all the time but it outputs the faulty output as previously reported. I believe the ESP is Rebooting when the VMicro SerialMonitor is active but waking up (correctly) when the Arduino SerialMonitor is active.

I will change the program to rerout the Serial output to a UART and monitor that to see if there is any difference.

Below is the compiler output, unfortunately I am unable to supply the same for Arduino as it will not let me right click and copy the screen output.
« Last Edit: Jun 27th, 2023 at 4:23pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #3 - Jun 27th, 2023 at 4:24pm
Print Post  
Please follow the guide in yellow above and attach or email a .txt file. pasting the output as code does not work properly.

In arduino you can use the keyboard to select all and copy. 

Also post a picture of the visual micro serial monitor do that we can see the state of the dtr and rts buttons.
« Last Edit: Jun 27th, 2023 at 4:26pm by Tim@Visual Micro »  
Back to top
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #4 - Jun 27th, 2023 at 5:38pm
Print Post  
The problem turns out NOT to be Same program Compiled on Arduino and VMicro producing different executables.

The problem is that the Exercutable behaves differently when Serial output is sent to USB.
When the program sends it's output to the Arduino Serial Monitor it performs as it should, on the other hand when the output is sent to the VMicro Serial Monitor it seems to cause the ESP32 to Reboot/Reset when it wakes up.

I re-wrote the code so that, with exception of one "Hello", the output was diverted to Serial1.
This was picked up by a Teensy and outputted to it's USB Serial for inspection.

The two outputs are in the attached files.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #5 - Jun 27th, 2023 at 5:47pm
Print Post  
Not that I think it's important but the two Board Properties files are attached.

The program is now:
Code (C++)
Select All
/*
Simple Deep Sleep with Timer Wake Up
=====================================
ESP32 offers a deep sleep mode for effective power
saving as power is an important factor for IoT
applications. In this mode CPUs, most of the RAM,
and all the digital peripherals which are clocked
from APB_CLK are powered off. The only parts of
the chip which can still be powered on are:
RTC controller, RTC peripherals ,and RTC memories

This code displays the most basic deep sleep with
a timer to wake it up and how to store data in
RTC memory to use it over reboots

This code is under Public Domain License.

Author:
Pranav Cherukupalli <cherukupallip@gmail.com>
*/

#include <HardwareSerial.h>
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  10        /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount;// = 0;

//HardwareSerial Serial1(1);
/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason()
{
    esp_sleep_wakeup_cause_t wakeup_reason;

    wakeup_reason = esp_sleep_get_wakeup_cause();

    switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT0: Serial1.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1: Serial1.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER: Serial1.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial1.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP: Serial1.println("Wakeup caused by ULP program"); break;
    default: Serial1.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
    }
}

void setup()
{
    Serial.begin(115200);

    Serial1.begin(115200, SERIAL_8N1, 20, 21);// RXD1, TXD1);
    delay(1000); //Take some time to open up the Serial Monitor

    //Increment boot number and print it every reboot
    ++bootCount;
    Serial.println("Hello");
    Serial.flush();
    delay(100);
    Serial1.println("Boot number: " + String(bootCount));

    //Print the wakeup reason for ESP32
    print_wakeup_reason();

    /*
    First we configure the wake up source
    We set our ESP32 to wake up every 5 seconds
    */
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    Serial1.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");

    //GPIO3   1ULL << 3
    //esp_deep_sleep_enable_gpio_wakeup(1ULL << 3,ESP_GPIO_WAKEUP_GPIO_HIGH);

    /*
    Next we decide what all peripherals to shut down/keep on
    By default, ESP32 will automatically power down the peripherals
    not needed by the wakeup source, but if you want to be a poweruser
    this is for you. Read in detail at the API docs
    http://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.html
    Left the line commented as an example of how to configure peripherals.
    The line below turns off all RTC peripherals in deep sleep.
    */
    //esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
    //Serial.println("Configured all RTC Peripherals to be powered down in sleep");

    /*
    Now that we have setup a wake cause and if needed setup the
    peripherals state in deep sleep, we can now start going to
    deep sleep.
    In the case that no wake up sources were provided but deep
    sleep was started, it will sleep forever unless hardware
    reset occurs.
    */
    delay(3000);
    Serial1.println("Going to sleep now");
    Serial1.flush();
    delay(100);
    esp_deep_sleep_start();
    Serial1.println("This will never be printed");
}

void loop()
{
    //This is not going to be called
}
 

  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #6 - Jun 27th, 2023 at 6:06pm
Print Post  
Further interesting Anomaly.

I thought that the problem was caused by writing to the VMicro Serial Mpnitor so I deleted ALL the references to Serial. just using Serial1 directed to the Teensy Serial Port.

I thought that this would/might give a normal output. No such luck. If the VMicro Serial Monitor was open then the output alternated between one good output followed by one "Reset" output.

If the VMicro Serial Monitor was closed then everything operated as it should. Why on-earth should the presence of a serial monitor not being written to cause such a problem.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #7 - Jun 27th, 2023 at 6:29pm
Print Post  
It's all a bit simpler than you might expect. Visual Micro just follows the build instructions for each board. The serial monitor is not connected directly to any code.

I asked for a screen shot of the serial monitor because it is possible you have enabled the dtr or rts. Please show screen shot thanks.
  
Back to top
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #8 - Jun 27th, 2023 at 6:37pm
Print Post  
Attached screen shot at z.png
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #9 - Jun 27th, 2023 at 7:34pm
Print Post  
You have dtr and rts selected. I believe they are off by default for esp32. Please switch them off
  
Back to top
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #10 - Jun 28th, 2023 at 9:58am
Print Post  
I was full of hope this morning but turning off DTS and RTS made NO difference.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #11 - Jun 28th, 2023 at 11:11am
Print Post  
Try switching off the auto reconnect.
  
Back to top
IP Logged
 
BriComp
Newbies
*
Offline


Posts: 9
Location: Cheltenham, UK
Joined: May 11th, 2021
Re: VMicro compiles Source which Does NOT work properly whilst it is Fine on the Arduio IDE
Reply #12 - Jun 29th, 2023 at 11:00am
Print Post  
No, that did not sort it either, but don't worry about it from my perspective.

I have been struggling with this for over a week, thinking that the ESP32C3 deepsleep did not work for the Arduino IDE (and VMicro IDE).

Now that I know that it does work, but not with Serial Monitor open, I can work around the problem.

Thank you for your help.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: ESP32 deep sleep fails when serial monitor is open
Reply #13 - Jun 29th, 2023 at 11:05am
Print Post  
We will give it a try thanks
  
Back to top
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2441
Joined: Feb 13th, 2019
Re: ESP32 deep sleep fails when serial monitor is open
Reply #14 - Jun 30th, 2023 at 8:20am
Print Post  
We are struggling to reproduce the problem with an EXP32-C3-DevkitC-02 Board currently, with the same 2.0.9 ESP32 board package and the code example you have posted.   

We have enabled the USB CDC On Boot option as your logs show, and output all messages via Serial1, which correctly count up as expected once the serial monitor is opened and left open.

From your output it is seems that the random resets could be caused by the brownout detector from my understanding:
rst:0x15 (USB_UART_CHIP_RESET),boot:0xd (SPI_FAST_FLASH_BOOT)

The rst: 0x15 tallies with the Brownout reset shown here: https://github.com/espressif/esp-idf/blob/release/v5.0/components/esp_rom/includ...

Can you confirm exactly which board you have, and if possible provide a link to it?

Can you also try changing the USB lead or Power supply to the board just in case this helps?
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint