1

For debugging purposes I want my serial connection to resume after sleep. After running LowPower.sleep() from the <ArduinoLowPower.h> library, I don't get any new serial messages in the serial monitor.

Several factors seem to be at play (which I've listed at the bottom) and I've developed a partial solution but it's not great because it requires some long artificial delays of about 1 second after each sleep to resume the serial. So to recap, my question is how I can get serial to work after sleeping the microcontroller without having to insert long delays.

For background, I am using an Adafruit Feather M0, which I think actually uses SerialUSB and automatically converts serial commands to that according to the guide, but I am not sure what any of that means.

Here's some stuff I looked into:

  1. COM Port: One factor is that the Arduino disconnects from the my Windows 10 computer at sleep and reconnects when it wakes up sometimes on a different COM port. Using the program Tera Term instead of the Arduino IDE Serial Monitor seems to keep it on the same COM port.

  2. Serial Flush and End: As notes in my code example, both of these commands seem necessary before sleeping or else I won't receive new messages after sleep.

  3. Delay: Seems that the arduino can send messages right after waking up that Tera Term wont see. I have to put a delay of 1 full second after waking up or else I won't see the messages.

Here's some code I have tried.

#include <ArduinoLowPower.h>

void setup() {
  Serial.begin(115200);
  while(!Serial){delay(10);}
  Serial.println("start");
}

void loop() {

  Serial.println("");
  Serial.println("sleep");
  Serial.flush();  //if this line is commented out, only one cycle of "sleep" will show
  Serial.end();   //if this line is commented out, only one cycle of "sleep" will show
  //delay(2000);  //doesn't seem to fix anything so commented out
  LowPower.sleep(2000);
  delay(1000);  //at 750 misses some "awake" messages
  //Serial.begin(115200);  //this line doesn't appear to fix anything so commented out
  Serial.println("awake");

Output:

start

sleep
awake

sleep
awake

sleep
awake
2
  • while (!Serial);? – Juraj Apr 11 at 16:27
  • so i have a chance to open the serial on my computer before it goes nuts – rfii Apr 15 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.