Xiao ESP32 s3 Serial Monitor not working

I am beginning to work with a Seeed product for the first time. I am using Arduino in the VSCode editor with PlatformIO. I set the program to use the seeed_xiao_esp32s3 board and environment. I wanted to try an old program. It blinks, reads touch pin values, sleeps, and then wakes back up. I can upload the program, it seems to run, I can execute a reset with the r button. I however cannot see anything on the serial monitor. In fact, as soon as the serial port is monitored, I get a message that the serial port is closed “due to disconnection from the machine”.

I’d love some help here.

I’ll try and attach a screen shot here:

Here is the code for the program.
#include <Arduino.h>
#include <Adafruit_Sleepydog.h>
#include <ESP32Time.h>
#include <esp_sleep.h>

int shrt;
int lng;
int hall;
int touchValue;
int touchpin = 4;
int touchtotal;

void shortblink(int blinks);
void longblink(int blinks);

// Define the touchpad sensitivity
#define Threshold 20

// Function reference for a wake callback function
void touchCallback();

void setup() {
//setCpuFrequencyMhz(80);
Serial.begin(9600);

Serial.println("");
Serial.println("… Waking from deep sleep …");
Serial.println("");

// Set up the deep sleep timmer to sleep for 10 seconds
esp_sleep_enable_timer_wakeup(1000000 * 10);

// Enable the touch pad functin as a wake up source
esp_sleep_enable_touchpad_wakeup();
// Now call the function for touchpad wake up
touchAttachInterrupt(4, touchCallback, Threshold);

// initialize LED digital pin as an output.
pinMode (LED_BUILTIN, OUTPUT);
digitalWrite (LED_BUILTIN, LOW);

// assign beginning values short and long variables
shrt = 3;
lng = 1;

}

void loop() {

// Call function to perform the 1st short blinks
shortblink(shrt);
delay(500);

// Second loop to blink long blinks.
longblink(lng);
delay(500);

// Call function to perform the 2nd short blinks
shortblink(shrt);
delay(500);

// Read 5 touch values and average them
touchValue = 0;
touchtotal = 0;
for (int i=0; i<5; i++) {
touchValue = touchRead(touchpin);
touchtotal = touchtotal + touchValue;
}
touchValue = touchtotal / 5;
Serial.print(“Average Touch value = “);
Serial.println(touchValue);
Serial.println(””);
delay(2);

// Put the program to sleep for 10 seconds
//Note, wake up is a complete reboot
Serial.println(" … Entering deep sleep mode …");
Serial.flush();
esp_deep_sleep_start();
}

void shortblink(int blinks) {
for (int i=0; i<blinks; i++) {
digitalWrite (LED_BUILTIN, HIGH);
delay(100);
digitalWrite (LED_BUILTIN, LOW);
delay(100);
}
}

void longblink(int blinks) {
for (int i=0; i<blinks; i++) {
digitalWrite (LED_BUILTIN, HIGH);
delay(500);
digitalWrite (LED_BUILTIN, LOW);
delay(500);
}
}

// The function definition for the wake up callback
void touchCallback() {
// Leave blank
// By default the blank function restarts program from beginning
}

Hi,
After listening to your description, the problem you encountered should be that xiaoesp32s3 cannot be awakened. This is because xiaoesp32s3 is in a deep sleep state and needs to wake up in a proper way
Relevant way I write in the wiki: Getting Started | Seeed Studio Wiki

Hi Jostar,

Thanks for the reply. I have continued to do some work in the meantime. First let me comment on your reply.

Here is the command you reference as the correct way to wake up: esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

Here is the command I am using to wake up:
esp_sleep_enable_timer_wakeup(1000000 * 10);

They are the same command. Therefore it is clear I am using the proper way to wake the esp32 up.

I have taken my program, that runs fine on other chips by the way, so the program is valid, and commented out all touch related code as a wake up reasons. So the code only relies on the timer.

The code will only run if VSCode is active and the serial monitor is active. The code loops a random number of times, between 3 and 15 times, then hangs. If VSCode is not active, meaning closed, then the code will runs through the blink cycle once and hangs.

There is clearly something wrong here, and it is not the code.

Any hints here?

Hi,robgreen:
I guess you probably used the wrong parameter in the command because you didn’t see the comment I wrote,
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
In the first definition I set TIME_TO_SLEEP to 5 and us_TO_S_FACTOR to 1000000; I also made a comment on the function

 /*
  First we configure the wake up source
  We set our ESP32 to wake up every 5 seconds
  */

This means that the TIME_TO_SLEEP parameter is the frequency to wake up ESP32C3 (I set it to wake up once in 5s), but you used the wrong parameter to wake up once in 1000000 seconds, which is a bit crazy! :smiley:You can try again according to my reply. If you still have any questions, you can follow up. I will reply to you as soon as I see it

Jostar

Hi Jostar,

I am confused. I use numbers in my sleep command. The Xiao example uses variable values. I am posting the Xiao variable declarations here. These variable values show that time is measured in microseconds, and the large number is needed as a conversion factor if we input seconds.

So, the Xiao variables ask the Xiao to wake up in 5 seconds. I am asking the program to wake up in 10 seconds. Both my and SEEED numbers are converted by 1,000,000 to convert to microseconds. Look at the SEED Xiao code, you see it there. Please read and understand the code SEEED posts on the website. I should not be doing that for you.

If you have hints, great, but let’s not trade around simple no thought text script ideas. If you don’t know say so. Please don’t waste my time.

Hi,
Please understand that English, as my second language, may have misinterpreted your meaning. What you want to express is that there is no problem with the program running, just a problem with the serial port

Turns out that there are different esp32 commands to wake from deep sleep with touch depending on which esp32 chip is used. All examples out there on the internet use the command “esp_sleep_enable_touchpad_wakeup();” This command does not work for all esp32 chips.

For the ESP32S3, the command is: “touchSleepWakeUpEnable(touchPin, Threshold);” where touchPin is a variable assigning a specific pin, and Threshold is a variable setting sensitivity. The Espressif recommended ESP32S3 setting is 80000. Lower numbers are more sensitive. I ended up using a sensitivity number that was much lower, like below 10000.

I only found this after digging into the Espressif Github. Once I was using the correct command to enable touch wake up, all worked well. I love the Xiao as it is lower current draw than something like the Adafruit BO ESP32.

1 Like