Description
sleep()
– puts the device into low power mode.
sleep( uint32_t u32_sleeptime_ms )
– puts the device into low power mode and wakes up triggered by the RTC.
Syntax
LowPower.sleep( u32_sleeptime_ms );
LowPower.sleep();
Parameters
uint32_t – time in milliseconds to stay in sleep mode (if not triggered by any other wake up source)
Returns
uint8_t – reports one or several reasons that caused the system to wake up:
- LOWPOWER_WKUP_IGN
- LOWPOWER_WKUP_RTC
- LOWPOWER_WKUP_ACC
- LOWPOWER_WKUP_CAN0
- LOWPOWER_WKUP_CAN1
- LOWPOWER_WKUP_USB
Example Code
The following example configures the device to wake up after 10 seconds and at a L/H transition on the ignition pin.
#include "LowPowerSAMC.h"
void setup()
{
LowPower.setWkUpSources( LOWPOWER_WKUP_IGN | LOWPOWER_WKUP_RTC );
}
void loop ()
{
digitalWrite(LED_BUILTIN, LOW);
uint8_t u8_ret = LowPower.sleep(10000);
Serial.print("Wakeup reason: ");
if(u8_ret & LOWPOWER_WKUP_IGN) Serial.println("IGNITION");
if(u8_ret & LOWPOWER_WKUP_RTC) Serial.println("RTC");
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
}
Notes:
Please note that the sleep() function can be called without any time-argument. Use it without argument if you would like to wake the device at a particular time (note that the RTC needs to be set to the correct time)
The sleep method also controls the 5V converter. The converter will be switched off when the sleep mode is entered and will be enabled again when woken up. This also disables the supply of the communication modules (e.g. wifi) and the CAN transceivers during sleep.
Examples can be found in the Arduino IDE menu:
File -> Examples -> LowPowerSAMC
File -> Examples -> RTCSAMC ->
See also
setWkUpSources()
SELFHOLD – see the device specific #defines for PINs
Users manual – block diagrams explaining the involved converter (5V) and internal signals (SELFHOLD, IGN, ACC_WKUP etc.)