Dependancies
periodic-wakeup.ino
#include <ArduinoLowPower.h>
#define LED 13
void setup() {
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
// Serial1 UART is used because the USB does not work after wakeup
Serial1.begin(9600);
// while (!Serial1) {}
delay(1000);
Serial1.println("Start of program");
Serial1.println("Fast blink 10 times");
blink(10, 200);
}
void loop() {
Serial1.println("Slow 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, LOW);
delay(duration);
digitalWrite(LED, HIGH);
delay(duration);
}
}
BOARD?=arduino:samd:mzero_bl
PORT := $(shell ls /dev/cu.usbmodem*)
.PHONY: default lint all flash clean
default: lint all flash clean
lint:
cpplint --extensions=ino --filter=-legal/copyright *.ino
all:
arduino-cli compile --fqbn $(BOARD) ./
flash:
arduino-cli upload -p $(PORT) --fqbn $(BOARD) ./
clean:
rm -f .*.bin
rm -f .*.elf
rm -f .*.hex
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.