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
}