This chapter describes the various methods for sleep and wakeup which are embedded in Pytrack and Pysense libraries. Both Pytrack and Pysense have the same methods, although the appropriate class, either pytrack
or pysense
, has to be instantiated.
An example is available at Sleep Wakeup Example Libraries GitHub repository and here
In the event of a sleep session that was awoken by an asynchronous event (Accelerometer, INT pin or Reset button) the approximate sleep remaining interval (expressed in seconds) can be found out. The user has to manually use setup_sleep()
to configure the next sleep interval.
Returns the last wakeup reason. Possible values are:
# WAKE_REASON_ACCELEROMETER = 1 # Accelerometer activity/inactivity detection
# WAKE_REASON_PUSH_BUTTON = 2 # Pytrack/Pysense reset buttom
# WAKE_REASON_TIMER = 4 # Normal timeout of the sleep interval
# WAKE_REASON_INT_PIN = 8 # INT pin
Note: the WAKE_REASON_INT_PIN
can be used if the PIC_RC1
pin (pin#6 on External IO Header) is toggled.
As in the above example, this method should be called at the beginning of the script, to find out the reset (wakeup) reason.
Puts the board in sleep mode, for the duration, which has to be set previously with pytrack.setup_sleep(timout_sec)
. The optional boolean parameter sets the GPS state during sleep.
MicroPython code, which is after this function, is not executed, as wakeup will restart MicroPython.
Enables as wakeup source, the accelerometer INT pin (PIC - RA5). The boolean parameters will indicate rising edge (activity detection) and/or falling edge (inactivity detection) is configured.
The accelerometer (class LIS2HH12
**)** has to be also configured for a certain acceleration threshold and duration. Code snippet:
from pytrack import Pytrack
from LIS2HH12 import LIS2HH12
py = Pytrack()
acc = LIS2HH12()
# enable activity and also inactivity interrupts, using the default callback handler
py.setup_int_wake_up(True, True)
# set the acceleration threshold to 2000mG (2G) and the min duration to 200ms
acc.enable_activity_interrupt(2000, 200)
Enables as wakeup source, the INT pic (PIC - RC1, pin#6 on External IO Header). Either rising or falling edge has to be set, by default it’s rising edge.
Sets the sleep interval, specified in seconds. The actual sleep will be started by calling go_to_sleep()
method.
Warning: When running via the repl calling setup_sleep()
will hang/crash the repl. this is not the case for scripts uploaded to the board.
Please note that more functionality is being added weekly to these libraries. If a required feature is not available, feel free to contribute with a pull request at the Libraries GitHub repository