Ways to sleep Pytrack
-
I'm trying to understand the difference between the various ways that you can sleep using a Pytrack (with WiPy3). I'm not clear about what is the appropriate use of each sleep mode and how it interacts with user interrupts as well as interrupts from the accelerometer or GPS. Here is what I understand thus far:
machine.idle()
- Active (not a sleep mode)
- Used to decrease power consumption while still running board
time.sleep([sec])
ortime.sleep_ms([milli_sec])
- User interrupt: Ctrl+F, reset button
- Not deep sleep
- Wake up using all interrupts
- Use: put delays in code
utime.sleep([sec])
- User interrupt: Ctrl+F, reset button
- Not deep sleep
- Wake up using all interrupts
- Use: put delays in code
- MicroPy version of #1
Timer.sleep_us([micro_sec])
- Does not appear to do anything...
machine.deepsleep([milli_sec])
- User interrupt: Reset button
- Deep sleep (resets board upon wake up and runs
boot.py
andmain.py
) - Use: deep sleep for low power consumption
- Built-in Interrupt: Pin (e.g.
machine.pin_deepsleep_wakeup(['P14'], machine.WAKEUP_ALL_LOW, False)
)
pytrack.go_to_sleep()
- User interrupt: Disconnect and reconnect power to device
- Deep sleep (resets board upon wake up and runs
boot.py
andmain.py
) - Initialize sleep duration using
pytrack.setup_sleep([sec])
- Use: deep sleep for low power consumption
- Built-in interrupt: accelerometer (e.g.
acc.enable_activity_interrupt(2000, 400, 100, handler=my_activity_handler)
) or input on PIC - RC1, Pin#6 on External IO Header
My overall goal is to sleep the board for some time with low power consumption, wake up, take an accelerometer and GPS reading, record values to SD card, then go back to sleep. I would also like to allow for sleep interrupts from the accelerometer (e.g. values greater than 3g would wake the board, record the value, then go back to sleep for remaining time). It is also important to be able to have a user reset to allow the board to connect to the REPL when needed. A basic explanation of this would be much appreciated!
-
@alexpul if you want low power it’s going to be one of the last two. On a WiPy 3 the recommended option is
machine.deepsleep
, though I haven’t checked whether it can be used with wake-on-accelerometer. You probably won’t be able to capture the acceleration at the actual time it is over 3g, though, it takes a little while for the WiPy to wake up...