Gen3 Sleep - Sleep for time only?

I am looking at the spec for the new Sleep functionality now available on Gen3 devices. However, it is not clear how to use sleep() if I am only interested in sleeping for a certain amount of time without waking up using a pin.

How should I call this function?

That is possible for STOP mode, but not STANDBY mode on Gen 3 hardware due to limitations fo the RTC on the nRF52840.

You can read more about support for Gen 3 devices like the Argon, Boron, and Xenon in our documentation, here:

https://docs.particle.io/reference/device-os/firmware/boron/#sleep-sleep-

I hope that helps to answer your question!

1 Like

Looks like this is what you want:

System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds) can be used to put the entire device into a stop mode with wakeup on interrupt or wakeup after specified seconds. In this particular mode, the device shuts network subsystem and puts the microcontroller in a stop mode with configurable wakeup pin and edge triggered interrupt or wakeup after the specified seconds. When the specific interrupt arrives or upon reaching the configured timeout, the device awakens from stop mode. The device will not reset before going into stop mode so all the application variables are preserved after waking up from this mode. The voltage regulator is put in low-power mode. This mode achieves the lowest power consumption while retaining the contents of RAM and registers.

// EXAMPLE USAGE

// Put the device into stop mode with wakeup using RISING edge interrupt on D1 pin or wakeup after 60 seconds whichever comes first
System.sleep(D1,RISING,60);
// The device LED will shut off during sleep

I guess you use an unused pin if you only want a time based sleep.

@nathanja was your question answered?

@will @Fragma @KyleG thanks for your help. What I mean is, is there a version of the function where a pin and a trigger mode don’t need to be specified? Or perhaps NULL could be put in their place?

And if I need to use an “unused pin”, what would be best?

NULL won’t work as this would just evaluate to 0 which in turn means D0.
But you can use PIN_INVALID or an empty pin list (e.g. System.sleep( {}, {}, 60);).

5 Likes

Good question. Good workaround from @ScruffR
I have not tested this but another potential approach could be to use the wake reason like the example given in the reference documents [BTW who ever thought of including this :+1:]

SleepResult result = System.sleepResult();
if (result.wokenUpByRtc()) {
  Log.info("Xenon was woken up by the RTC (after a specified number of seconds)");
}
2 Likes

I like it! Seems like a pure time-based sleep should be its own method at some point though. Thank you!