XIAO MG24 Sense Low Power Library weirdness

So I feel like I’m taking crazy pills. I got the new MG24, and want to go as low power consumption as possible with it. The below code is slightly simplified from Getting Started with Seeed Studio XIAO MG24 | Seeed Studio Wiki

#include "ArduinoLowPower.h"

void setup()
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
  Serial.println("Sleep with timed wakeup");
}

void loop()
{
  digitalWrite(LED_BUILTIN, LED_BUILTIN_ACTIVE);
  delay(500);
  digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
  delay(500);

  Serial.printf("Going to sleep at %lu\n", millis());
  LowPower.sleep();
  Serial.printf("Woke up at %lu\n", millis());
}

Based on my understanding, with LowPower.sleep(); the program should blink the LED once and then go to sleep and never blink again. Am I wrong in that? Because what actually happens is that it continues to loop forever as if LowPower.sleep(); wasn’t there at all.

What’s happening here?

In your code, LowPower.sleep() is called, but the microcontroller immediately wakes up due to internal interrupts or watchdog mechanisms, and the loop() resumes execution.
The LED blinking and Serial.printf() outputs confirm that the microcontroller isn’t staying in sleep mode long enough to appear “stopped.”
You can modify the code like this:

#include "ArduinoLowPower.h"

void setup()
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
  Serial.println("Sleep with timed wakeup");
}

void loop()
{
  // Blink LED
  digitalWrite(LED_BUILTIN, LED_BUILTIN_ACTIVE);
  delay(500);
  digitalWrite(LED_BUILTIN, LED_BUILTIN_INACTIVE);
  delay(500);

  // Log message and sleep
  Serial.printf("Going to sleep at %lu ms\n", millis());
  
  // Sleep with a timer wakeup for 5 seconds
  LowPower.sleep(5000);
  
  Serial.printf("Woke up at %lu ms\n", millis());
}

Thanks. That is true I could add a timer, but I really wanted it to sleep indefinitely

Hi there,

I would only add maybe , Does it require and “Serial Flush” and then a “Serial End” (to stop the Serial Begin) ? for the Light Sleep with Timer wakeup.
my .02

HTH
GL :slight_smile: PJ :v:

Take a look at some of the Sleep demo’s on here and get the jist of the pre and post steps sometimes required(register writes & delay’s) as @liaifat85 points out , this device is New so the info is tight. :ok_hand:

Thanks @PJ_Glasso. I tried playing around with those and it didn’t seem to fix the issue. Weird!

Hi there,

Yea, @msfujino is also looking into it, appears that maybe different methods are required for the different levels of Sleep. Hmmm :face_with_peeking_eye:
Just because I like hearing myself; I would have checked if this device meets the minimum requirements in any New Xiao’s today.

  • Battery Monitor

  • Interrupts

  • Sleep modes

  • RTC

Then get cute with Peripherals, FastSPI, CAN bus, Dual Radio’s (concurrent)
i3C , WiF6, 5G , IOT.
Then have the Stacks or SD’s to back it… Zigbee, Thread, Matter, 4Mb PHY…
:star_struck: Someone kick me I’m dreaming…LOL

Anyway, expect the weirdness to continue Until we get the full 411 on this thing, until then for that reason , Like M Cuban "I’m Out "

NORDIC…
:yum:
Happy New year!!!

Thanks a lot @PJ_Glasso! I’m fairly new to all this, so just trying to find the best inexpensive, tiny, and power efficient microcontroller I can. $10 fit the bill nicely, but you are right, the newness of it is making it difficult at the moment. Appreciate you responding to all my posts on here. HNY!