Periodic wakeup with SAMD21

arduino m0 samd21 robotdyn wakeup sleep periodic

Sleep for 30 minutes and wakeup to make 10 LED blinks before going back to sleep again for another 30 minutes.

Note that the serial prints will not work after wakeup. Hence use a USB to UART chip to get the Serial1 prints. This is because during sleep, the entire USB peripheral also sleeps along with the MCU, except for the RTC.

During sleep, only power indicator green LED ON will be lighted on the RobotDyn dev board.

Code

Download code
#include <ArduinoLowPower.h>

void setup() {
  // Serial1 UART is used because the USB does not work after wakeup
  Serial1.begin(9600);
  while (!Serial1) {}
  delay(1000);

  Serial1.println("Start of program");
  blink(10, 200);

  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  Serial1.println("Blink 10 times");
  blink(10, 1000);

  Serial1.println("Going to sleep for 10 seconds...");

  LowPower.sleep(10000);  // in milliseconds

  Serial1.println("\n\nAwake");

  Serial1.println("Blink 5 times");
  blink(5, 1000);
}

void blink(int times, int duration) {
  for (int i = 0; i < times; i++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(duration);

    digitalWrite(LED_BUILTIN, LOW);
    delay(duration);
  }
}

Serial console

Serial output from the firmware.

Periodic wakeup with SAMD21 serial console

Prototype

A photo of the actual setup.

Periodic wakeup with SAMD21 prototype

Schematic

Wire up the hardware accordingly

Periodic wakeup with SAMD21 schematic

References