diff --git a/config.toml b/config.toml index c00e19a..ad7ffe5 100644 --- a/config.toml +++ b/config.toml @@ -419,6 +419,12 @@ theme = "doc-theme" identifier = "tutorials@expansionboards@pyscan" parent = "tutorials@expansionboards" weight = 60 +[[menu.main]] + name = "Sleep" + url = "/tutorials/expansionboards/sleep/" + identifier = "tutorials@expansionboards@sleep" + parent = "tutorials@basic" + weight = 20 [[menu.main]] name = "Advanced" url = "/tutorials/advanced/" diff --git a/content/firmwareapi/pycom/expansionboards/sleep.md b/content/firmwareapi/pycom/expansionboards/sleep.md index bb92ce8..825d41b 100644 --- a/content/firmwareapi/pycom/expansionboards/sleep.md +++ b/content/firmwareapi/pycom/expansionboards/sleep.md @@ -10,44 +10,7 @@ This chapter describes the various methods for sleep and wakeup which are embedd ## Quick Usage Example -The following example is also available at [Sleep Wakeup Example Libraries GitHub repository](https://github.com/pycom/pycom-libraries/blob/master/examples/accelerometer_wake/main.py) - -```python - -#from pytrack import Pytrack -from pysense import Pysense -from LIS2HH12 import LIS2HH12 -import time - -#py = Pytrack() -py = Pysense() - -# display the reset reason code and the sleep remaining in seconds -# possible values of wakeup reason are: -# WAKE_REASON_ACCELEROMETER = 1 -# WAKE_REASON_PUSH_BUTTON = 2 -# WAKE_REASON_TIMER = 4 -# WAKE_REASON_INT_PIN = 8 - -print("Wakeup reason: " + str(py.get_wake_reason())) -print("Approximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec") -time.sleep(0.5) - -# enable wakeup source from INT pin -py.setup_int_pin_wake_up(False) - -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) - -# go to sleep for 5 minutes maximum if no accelerometer interrupt happens -py.setup_sleep(300) -py.go_to_sleep() -``` +An example is available at [Sleep Wakeup Example Libraries GitHub repository](https://github.com/pycom/pycom-libraries/blob/master/examples/accelerometer_wake/main.py) and [here](/tutorials/expansionboards/sleep/) ## Methods diff --git a/content/tutorials/basic/sleep.md b/content/tutorials/basic/sleep.md index 9c8550b..15130e3 100644 --- a/content/tutorials/basic/sleep.md +++ b/content/tutorials/basic/sleep.md @@ -82,34 +82,4 @@ print("This will never be printed") >Note: Using `deepsleep()` will also stop the USB connection. Be wary of that when trying to upload new code to the device! -#### Other methods - -The expansionboards (Pysense 2.0 X, and Pytrack 2.0 X, DeepSleep shield) use a different mechanism to put the controller to sleep. A separate controller on the expansion board will put the main controller to sleep. This will actually cut all power from the module for the set amount of time, hard resetting it. Cutting power to the expansion board will work as well. Using this method, we can still recover the wake up reason and remaining sleep time. The example below works was written for a Pysense, but works on any of the boards by changing the first lines - -```python -from pysense import Pysense -py = Pysense() -py.setup_sleep(10) # set sleep time of 10 seconds -py.go_to_sleep() -print("this will never be printed") -``` -Using this method, we can also wake the board using the accelerometer and external pin `P6` by rising (`True`) or falling (`False`) edge - -```python -from pysense import Pysense -from LIS2HH12 import LIS2HH12 - -py = Pysense() -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) - -py.set_int_pin_wake_up(True) #wake up on rising edge on pin 6 of the expansion header - -py.go_to_sleep()# the device will sleep indefinitely, until pin 6 goes high, or the accelerometer is triggered -``` -LTE Power saving mode (PSM) \ No newline at end of file +For the Pysense, Pytrack and Pyscan expansionboards, an additional sleep function is available. You can find out more about that [here](../expansionboards/sleep/) \ No newline at end of file diff --git a/content/tutorials/expansionboards/sleep.md b/content/tutorials/expansionboards/sleep.md new file mode 100644 index 0000000..e5b4dda --- /dev/null +++ b/content/tutorials/expansionboards/sleep.md @@ -0,0 +1,51 @@ +--- +title: 'Sleep' +--- + +The expansionboards (Pysense 2.0 X, and Pytrack 2.0 X, DeepSleep shield) use a different mechanism to put the controller to sleep. A separate controller on the expansion board will put the main controller to sleep. This will actually cut all power from the module for the set amount of time, hard resetting it. Cutting power to the expansion board will work as well. Using this method, we can still recover the wake up reason and remaining sleep time. The example below works was written for a Pysense, but works on any of the boards by changing the first lines + +```python +from pysense import Pysense +py = Pysense() +py.setup_sleep(10) # set sleep time of 10 seconds +py.go_to_sleep() +print("this will never be printed") +``` +Using this method, we can also wake the board using the accelerometer interrupt method: + +```python + +#from pytrack import Pytrack +from pysense import Pysense +from LIS2HH12 import LIS2HH12 +import time + +#py = Pytrack() +py = Pysense() + +# display the reset reason code and the sleep remaining in seconds +# possible values of wakeup reason are: +# WAKE_REASON_ACCELEROMETER = 1 +# WAKE_REASON_PUSH_BUTTON = 2 +# WAKE_REASON_TIMER = 4 +# WAKE_REASON_INT_PIN = 8 + +print("Wakeup reason: " + str(py.get_wake_reason())) +print("Approximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec") +time.sleep(0.5) + +# enable wakeup source from INT pin +py.setup_int_pin_wake_up(False) + +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) + +# go to sleep for 5 minutes maximum if no accelerometer interrupt happens +py.setup_sleep(300) +py.go_to_sleep() +``` \ No newline at end of file