Skip to content

Commit cf315bd

Browse files
committed
Adjust docs for uasyncio V2.0.
1 parent adc87b2 commit cf315bd

File tree

6 files changed

+66
-41
lines changed

6 files changed

+66
-41
lines changed

FASTPOLL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ with improved millisecond-level timing accuracy and reduced scheduling latency.
66

77
V0.2 Dec 2017. A single module designed to work with the official `uasyncio`
88
library. This requires uasyncio.core V1.7 which was released on 16th Dec 2017,
9-
with firmware of that date or later.
9+
with firmware of that date or later. It does not yet support `uasyncio` V2.0.
1010

1111
**API CHANGES**
1212
The API has been changed to simplify the code and to improve consistency.

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ This GitHub repository consists of the following parts:
1818
mechanism. With suitable application design this improves the rate at which
1919
devices can be polled and improves the accuracy of time delays. Also provides
2020
for low priority tasks which are only scheduled when normal tasks are paused.
21+
NOTE: this currently supports uasyncio V1.7.1.
2122
* [Communication between devices](./syncom_as/README.md) Enables MicroPython
2223
boards to communicate without using a UART. Primarily intended to enable a
2324
a Pyboard-like device to achieve bidirectional communication with an ESP8266.
2425

2526
# 2. Version and installation of uasyncio
2627

2728
This has become more involved owing to the development of Paul Sokolovsky's
28-
fork. At the time of writing this fork supports `uasyncio` version 2.0, which
29-
requires the build of firmware from his repository. The version on PyPI is
30-
V2.0.
29+
fork. At the time of writing his fork supports `uasyncio` version 2.0. The
30+
version on PyPI is also V2.0.
3131

32-
Until the situation becomes clearer I plan to support the official firmware.
33-
Hence these docs, code samples etc. are based on `uasyncio.core` V1.7.1 which
34-
is in [micropython-lib](https://github.com/micropython/micropython-lib).
32+
The version in [micropython-lib](https://github.com/micropython/micropython-lib)
33+
is version 1.7.1.
34+
35+
With the exception of the priority version all docs and code samples should be
36+
compatible with both versions. Testing has been done under V1.7.1.
3537

3638
See [tutorial](./TUTORIAL.md#installing-uasyncio-on-bare-metal) for
3739
installation instructions.

TUTORIAL.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,41 @@ features.
2222

2323
# Installing uasyncio on bare metal
2424

25-
As discussed in the [main README](./README.md) these instructions assume the
26-
official build of MicroPython firmware. Accordingly the `uasyncio` files from
27-
the [official library](https://github.com/micropython/micropython-lib) are
28-
required. At the time of writing the PyPI repository contains `uasyncio` V2.0
29-
which is incompatible with that fimware so `upip` cannot be used.
25+
MicroPython libraries are located on [PyPi](https://pypi.python.org/pypi).
26+
Libraries to be installed are:
27+
28+
* micropython-uasyncio
29+
* micropython-uasyncio.queues
30+
* micropython-uasyncio.synchro
31+
32+
The `queues` and `synchro` modules are optional, but are required to run all
33+
the examples below.
34+
35+
The oficial approach is to use the `upip` utility as described
36+
[here](https://github.com/micropython/micropython-lib). Network enabled
37+
hardware has this included in the firmware so it can be run locally. This is
38+
the preferred approach.
39+
40+
On non-networked hardware there are two options. One is to use `upip` under a
41+
Linux real or virtual machine. This involves installing and building the Unix
42+
version of MicroPython, using `upip` to install to a directory on the PC, and
43+
then copying the library to the target.
44+
45+
The need for Linux and the Unix build may be avoided by using
46+
[micropip.py](https://github.com/peterhinch/micropython-samples/tree/master/micropip).
47+
This runs under Python 3.2 or above. Create a temporary directory on your PC
48+
and install to that. Then copy the contents of the temporary direcory to the
49+
device. The following assume Linux and a temporary directory named `~/syn` -
50+
adapt to suit your OS. The first option requires that `micropip.py` has
51+
executable permission.
3052

31-
The aim is to create a `uasyncio` directory on the device's filesystem
32-
containing the following files:
33-
34-
[`__init__.py`](https://github.com/micropython/micropython-lib/blob/master/uasyncio/uasyncio/__init__.py)
35-
[`core.py`](https://github.com/micropython/micropython-lib/blob/master/uasyncio.core/uasyncio/core.py)
36-
[`queues.py`](https://github.com/micropython/micropython-lib/blob/master/uasyncio.queues/uasyncio/queues.py)
37-
[`synchro.py`](https://github.com/micropython/micropython-lib/blob/master/uasyncio.synchro/uasyncio/synchro.py)
53+
```
54+
$ ./micropip.py install -p ~/syn micropython-uasyncio
55+
$ python3 -m micropip.py install -p ~/syn micropython-uasyncio
56+
```
3857

39-
These modules may be frozen as bytecode in the usual way, by placing the above
40-
`uasyncio` directory in the port's `modules` directory and rebuilding.
58+
The `uasyncio` modules may be frozen as bytecode in the usual way, by placing
59+
the `uasyncio` directory in the port's `modules` directory and rebuilding.
4160

4261
###### [Main README](./README.md)
4362

@@ -169,7 +188,8 @@ The following modules are provided which may be copied to the target hardware.
169188
generalisation of switches providing logical rather than physical status along
170189
with double-clicked and long pressed events.
171190
3. `asyncio_priority.py` An experimental version of uasyncio with a simple
172-
priority mechanism. See [this doc](./FASTPOLL.md).
191+
priority mechanism. See [this doc](./FASTPOLL.md). Note that this does not yet
192+
support `uasyncio` V2.0.
173193

174194
**Demo Programs**
175195

auart.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Copyright Peter Hinch 2017 Released under the MIT license
44
# Link X1 and X2 to test.
55

6-
try:
7-
import asyncio_priority as asyncio
8-
except ImportError:
9-
import uasyncio as asyncio
6+
import uasyncio as asyncio
107
from pyb import UART
118
uart = UART(4, 9600)
129

htu21d/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
A breakout board is available from
44
[Sparkfun](https://www.sparkfun.com/products/12064).
55

6-
This driver was derived from the Pyboard specific driver
6+
This driver was derived from the synchronous Pyboard-specific driver
77
[here](https://github.com/manitou48/pyboard/blob/master/htu21d.py). It is
88
designed to be multi-platform and uses `uasyncio` to achieve asynchronous (non-
9-
blocking) operation. In most applications temperature and humidity values vary
10-
slowly. The driver maintains its `temperature` and `humidity` bound variables
11-
as a non-blocking background task. Consequently reading the values is
9+
blocking) operation. The driver maintains `temperature` and `humidity` bound
10+
variables as a non-blocking background task. Consequently reading the values is
1211
effectively instantaneous.
1312

1413
###### [Main README](../README.md)
@@ -44,4 +43,8 @@ async def show_values():
4443
fstr = 'Temp {:5.1f} Humidity {:5.1f}'
4544
print(fstr.format(htu.temperature, htu.humidity))
4645
await asyncio.sleep(5)
47-
```
46+
```
47+
48+
Thermal inertia of the chip packaging means that there is a lag between the
49+
occurrence of a temperature change and the availability of accurate readings.
50+
There is therefore little practical benefit in reducing the `read_delay`.

htu21d/htu_test.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
# Copyright Peter Hinch 2018 Released under the MIT license
55

66
import uasyncio as asyncio
7+
import sys
78
from machine import Pin, I2C
89
import htu21d_mc
910

10-
# Specify pullup: on my ESP32 board pullup resistors are not fitted :-(
11-
scl_pin = Pin(22, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
12-
sda_pin = Pin(23, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
13-
# Standard port
14-
i2c = I2C(-1, scl=scl_pin, sda=sda_pin)
11+
if sys.platform == 'pyboard':
12+
i2c = I2C(1) # scl=X9 sda=X10
13+
else:
14+
# Specify pullup: on my ESP32 board pullup resistors are not fitted :-(
15+
scl_pin = Pin(22, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
16+
sda_pin = Pin(23, pull=Pin.PULL_UP, mode=Pin.OPEN_DRAIN)
17+
# Standard port
18+
i2c = I2C(-1, scl=scl_pin, sda=sda_pin)
19+
# Loboris port (soon this special treatment won't be needed).
20+
# https://forum.micropython.org/viewtopic.php?f=18&t=3553&start=390
21+
#i2c = I2C(scl=scl_pin, sda=sda_pin)
1522

16-
# Loboris port (soon this special treatment won't be needed).
17-
# https://forum.micropython.org/viewtopic.php?f=18&t=3553&start=390
18-
#i2c = I2C(scl=scl_pin, sda=sda_pin)
19-
20-
htu = htu21d_mc.HTU21D(i2c, read_delay=2)
23+
htu = htu21d_mc.HTU21D(i2c, read_delay=2) # read_delay=2 for test purposes
2124

2225
async def main():
2326
await htu

0 commit comments

Comments
 (0)