6

I noticed something unusual using the Low Power library today. When printing text in the loop and using LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); to sleep for one second, all the text in the loop gets messed up in the Serial Monitor as if you chose the wrong baud rate.

Example code:

#include "LowPower.h"

void setup() {
  Serial.begin(9600);
  Serial.println(F("HELLO"));
  Serial.println(F("HELLO")); 
}

void loop() {
  Serial.println(F("HELLO"));
  LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}

This code just prints

����11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=C!�11=

even when using different baud rates. (I used the same baud rate on both the arduino and the monitor). Replacing the low power command with delay(1000); works fine

user3704293
  • 471
  • 7
  • 19
qwertz
  • 251
  • 1
  • 4
  • 8

1 Answers1

13

The problem is most likely that the system is going to sleep while it's still sending the serial data.

Forcing all the serial data to be sent before you go to sleep should fix the problem (serial data is sent in the background using an interrupt so as to keep sketch slowdown to a minimum):

Serial.flush();
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
Majenko
  • 105,851
  • 5
  • 82
  • 139