|
| 1 | +/* |
| 2 | + TianStandby |
| 3 | +
|
| 4 | + This sketch demonstrates the usage of SAMD chip to furtherly reduce the power usage of Tian |
| 5 | + board. This method can be applied to any board with companion chips which expose a method |
| 6 | + (via direct pin interrupt or via a command) to enter and exit standby. |
| 7 | + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. |
| 8 | +
|
| 9 | + In this sketch, the internal RTC of SAMD chip will wake up the processor every 20 seconds. |
| 10 | + Before going to sleep, the SAMD chip tells the MIPS CPU to standby too. |
| 11 | + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) |
| 12 | +
|
| 13 | + This example code is in the public domain. |
| 14 | +*/ |
| 15 | + |
| 16 | +#include "ArduinoLowPower.h" |
| 17 | + |
| 18 | +#define MIPS_PIN 32 |
| 19 | + |
| 20 | +void MIPS_PM(bool sleep) { |
| 21 | + pinMode(MIPS_PIN, OUTPUT); |
| 22 | + digitalWrite(MIPS_PIN, sleep ? LOW: HIGH); |
| 23 | +} |
| 24 | + |
| 25 | +void setup() { |
| 26 | + pinMode(LED_BUILTIN, OUTPUT); |
| 27 | + LowPower.companionLowPowerCallback(MIPS_PM); |
| 28 | + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip |
| 29 | + LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, onWakeup, CHANGE); |
| 30 | +} |
| 31 | + |
| 32 | +void loop() { |
| 33 | + digitalWrite(LED_BUILTIN, HIGH); |
| 34 | + delay(500); |
| 35 | + digitalWrite(LED_BUILTIN, LOW); |
| 36 | + delay(500); |
| 37 | + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) |
| 38 | + // The power consumption of the chip will drop consistently |
| 39 | + // Send sleep command to MIPS CPU and then go to sleep |
| 40 | + LowPower.companionSleep(); |
| 41 | + LowPower.sleep(20000); |
| 42 | +} |
| 43 | + |
| 44 | +void onWakeup() { |
| 45 | + // This function will be called once on device wakeup |
| 46 | + // You can do some little operations here (like changing variables which will be used in the loop) |
| 47 | + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context |
| 48 | + |
| 49 | + // Wakeup the companion chip, too |
| 50 | + LowPower.companionWakeup(); |
| 51 | +} |
0 commit comments