XIAO BLE Sense in deep sleep mode

?? strange serial behaviour
I added one more line to the code above … just suspend loop
and now serial monitor is printing every 3 seconds. It looks like the XIAO is firing the softwaretimer every 1 second but serial is sending output every 3 seconds. Strange !?

I still can not check if xiao is really “system-on sleeping” (and consuming less power) hence I don’t have precise meter. If not - I will try tu use hardware timer.
If someone could check this out …would be great :slight_smile:

#include <Arduino.h>
#include <Adafruit_TinyUSB.h> // for Serial
#include <bluefruit.h>

/* SoftwareTimer is a helper class that uses FreeRTOS software timer
 * to invoke callback. Its periodic timing is flexible as opposed to
 * hardware timer and cannot be faster than rtos's tick which is configured
 * at  ~1 ms interval.
 *
 * If you need an strict interval timing, or faster frequency, check out
 * the hw_systick sketch example that use hardware systick timer.
 *
 * http://www.freertos.org/RTOS-software-timer.html
 */
SoftwareTimer blinkTimer;

void setup()
{
  Serial.begin(115200);
  Bluefruit.begin();          // Sleep functions need the softdevice to be active.
  sd_power_mode_set(NRF_POWER_MODE_LOWPWR); 
  pinMode(LED_BUILTIN, OUTPUT);  // initialize digital pin LED_BUILTIN as an output.
  blinkTimer.begin(1000, blink_timer_callback);  // Configure the timer with 1000 ms interval, with our callback
  blinkTimer.start();  // Start the timer

  suspendLoop(); // Suspend Loop() to save power, since we didn't have any code there
}

void loop()
{
  // do nothing here , loop is already suspended, CPU will not run loop() at all
}

/**
 * Software Timer callback is invoked via a built-in FreeRTOS thread with
 * minimal stack size. Therefore it should be as simple as possible. If
 * a periodically heavy task is needed, please use Scheduler.startLoop() to
 * create a dedicated task for it.
 *
 * More information http://www.freertos.org/RTOS-software-timer.html
 */
void blink_timer_callback(TimerHandle_t xTimerID)
{
  // freeRTOS timer ID, ignored if not used
  (void) xTimerID;
  Serial.print("timer callback at - ");
  Serial.println(millis());
  digitalToggle(LED_BUILTIN);
  sd_app_evt_wait(); // puts the nrf52 to sleep when there is nothing to do
}

serial monitor output

...
13:40:50.928 -> timer callback at - 222418
13:40:50.928 -> timer callback at - 223418
13:40:50.928 -> timer callback at - 224418
13:40:53.951 -> timer callback at - 225418
13:40:53.951 -> timer callback at - 226418
13:40:53.951 -> timer callback at - 227418
13:40:56.952 -> timer callback at - 228418
13:40:56.952 -> timer callback at - 229418
13:40:56.952 -> timer callback at - 230418
...