|
1 | 1 | # A low power usayncio adaptation
|
2 | 2 |
|
3 |
| -Release 0.12 15th April 2019 |
| 3 | +Release 0.12 23rd April 2019 |
4 | 4 |
|
5 | 5 | API changes: low power applications must now import `rtc_time_cfg` and set its
|
6 | 6 | `enabled` flag.
|
@@ -75,12 +75,27 @@ tested. Copy the file `rtc_time.py` to the device so that it is on `sys.path`.
|
75 | 75 | very low power is consumed. A normally open pushbutton should be connected
|
76 | 76 | between `X1` and `Gnd`. This program is intended as a basic template for
|
77 | 77 | similar applications.
|
| 78 | + * `howlow.py` A lower power version of the above. Polls the switch every 200ms |
| 79 | + rather than running debouncing code. |
78 | 80 | * `lp_uart.py` Send and receive messages on UART4, echoing received messages
|
79 | 81 | to UART1 at a different baudrate. This consumes about 1.4mA and serves to
|
80 |
| - demonstrate that interrupt-driven devices operate correctly. |
| 82 | + demonstrate that interrupt-driven devices operate correctly. Requires a link |
| 83 | + between pins X1 and X2 to enable UART 4 to receive data via a loopback. |
| 84 | + * `mqtt_log.py` A publish-only MQTT application for Pyboard D. See below. |
81 | 85 |
|
82 |
| -The test program `lp_uart.py` requires a link between pins X1 and X2 to enable |
83 |
| -UART 4 to receive data via a loopback. |
| 86 | +`mqtt_log.py` requires the `umqtt.simple` library. This may be installed with |
| 87 | +[upip_m](https://github.com/peterhinch/micropython-samples/tree/master/micropip). |
| 88 | +``` |
| 89 | +>>> upip_m.install('micropython-umqtt.simple') |
| 90 | +``` |
| 91 | +This test is "experimental". Pyboard D support for low power WiFi is currently |
| 92 | +incomplete. I have seen anomolous results where power was low initially before |
| 93 | +jumping to ~30mA after a few hours. The application continued to run, but the |
| 94 | +evidence suggested that the WiFi chip was consuming power. See Damien's comment |
| 95 | +in [this issue](https://github.com/micropython/micropython/issues/4686). |
| 96 | +An option would be to shut down the WiFi chip after each connection. The need |
| 97 | +periodically to reconnect would consume power, but in applications which log at |
| 98 | +low rates this should avoid the above issue. Or wait for the firmware to mature. |
84 | 99 |
|
85 | 100 | ###### [Contents](./README.md#a-low-power-usayncio-adaptation)
|
86 | 101 |
|
@@ -135,11 +150,14 @@ loop = asyncio.get_event_loop()
|
135 | 150 | Latency(100) # Define latency in ms
|
136 | 151 | ```
|
137 | 152 |
|
138 |
| -The `Latency` class has a continuously running loop that executes `pyb.stop` |
139 |
| -before yielding with a zero delay. The duration of the `stop` condition |
140 |
| -(`latency`) can be dynamically varied. If zeroed the scheduler will run at |
141 |
| -full speed. The `yield` allows each pending task to run once before the |
142 |
| -scheduler is again paused (if `latency` > 0). |
| 153 | +`Latency` is a functor: its only interface is with function call syntax, which |
| 154 | +takes a single argument being the `lightsleep` duration in ms. If the lowpower |
| 155 | +mode is in operation the first call instantiates a coroutine with a |
| 156 | +continuously running loop that executes `pyb.stop` before yielding with a zero |
| 157 | +delay. The duration of the `lightsleep` condition can be dynamically varied by |
| 158 | +further `Latency(time_in_ms)` calls. If the arg is zero the scheduler will run |
| 159 | +at full speed. The `yield` allows each pending task to run once before the |
| 160 | +scheduler is again paused (if the current latency value is > 0). |
143 | 161 |
|
144 | 162 | The line
|
145 | 163 | ```python
|
@@ -392,16 +410,33 @@ async def bar():
|
392 | 410 |
|
393 | 411 | the 10ms sleep will be >=200ms dependent on other application tasks.
|
394 | 412 |
|
395 |
| -Latency may be changed dynamically by using the `value` method of the `Latency` |
396 |
| -instance. A typical application (as in `lpdemo.py`) might wait on a "Start" |
397 |
| -button with a high latency value, before running the application code with a |
398 |
| -lower (or zero) latency. On completion it could revert to waiting for "Start" |
399 |
| -with high latency to conserve battery. |
| 413 | +Latency may be changed dynamically by issuing `Latency(time_in_ms)`. A typical |
| 414 | +application (as in `howlow.py`) might wait on a "Start" button with a high |
| 415 | +latency value, before running the application code with a lower (or zero) |
| 416 | +latency. On completion it could revert to waiting for "Start" with high latency |
| 417 | +to conserve battery. Logging applications might pause for a duration or wait on |
| 418 | +a specific RTC time with a high latency value. |
| 419 | + |
| 420 | +Pyboard D users should note that firmware support for low power WiFi is |
| 421 | +incomplete. Consider turning off the WiFi chip when not in use: |
| 422 | +``` |
| 423 | +sta_if = network.WLAN() |
| 424 | +while True: |
| 425 | + # Wait for trigger |
| 426 | + sta_if.active(True) # Enable WiFi |
| 427 | + sta_if.connect(SSID, PW) |
| 428 | + # Use the network |
| 429 | + sta_if.deinit() # Turns off WiFi chip |
| 430 | +``` |
| 431 | +[ref](https://github.com/micropython/micropython/issues/4681) |
400 | 432 |
|
401 | 433 | ###### [Contents](./README.md#a-low-power-usayncio-adaptation)
|
402 | 434 |
|
403 | 435 | # 6. Note on the design
|
404 | 436 |
|
| 437 | +This module uses the old `pyb` in preference to `machine`. This is because the |
| 438 | +Pyboard 1.x `machine` module does not have an `RTC` class. |
| 439 | + |
405 | 440 | The `rtc_time` module represents a compromise designed to minimise changes to
|
406 | 441 | `uasyncio`. The aim is to have zero effect on the performance of applications
|
407 | 442 | not using `rtc_time` or ones running on non-Pyboard hardware.
|
|
0 commit comments