10
10
# Contents
11
11
12
12
0 . [ Introduction] ( ./TUTORIAL.md#0-introduction )
13
- 0.1 [ Installing uasyncio on bare metal ] ( ./TUTORIAL.md#01-installing-uasyncio-on-bare-metal )
13
+ 0.1 [ Installing uasyncio] ( ./TUTORIAL.md#01-installing-uasyncio )
14
14
1 . [ Cooperative scheduling] ( ./TUTORIAL.md#1-cooperative-scheduling )
15
15
1.1 [ Modules] ( ./TUTORIAL.md#11-modules )
16
16
  ;  ;  ;  ;  ; 1.1.1 [ Primitives] ( ./TUTORIAL.md#111-primitives )
@@ -92,7 +92,7 @@ source of confusion.
92
92
93
93
Most of this document assumes some familiarity with asynchronous programming.
94
94
For those new to it an introduction may be found
95
- [ in section 7 ] ( ./TUTORIAL.md#8-notes-for-beginners ) .
95
+ [ in section 8 ] ( ./TUTORIAL.md#8-notes-for-beginners ) .
96
96
97
97
The MicroPython ` uasyncio ` library comprises a subset of Python's ` asyncio `
98
98
library. It is designed for use on microcontrollers. As such it has a small RAM
@@ -105,24 +105,24 @@ responsive to events such as user interaction.
105
105
Another major application area for asyncio is in network programming: many
106
106
guides to this may be found online.
107
107
108
- Note that MicroPython is based on Python 3.4 with minimal Python 3.5 additions .
108
+ Note that MicroPython is based on Python 3.4 with additions from later versions .
109
109
This version of ` uasyncio ` supports a subset of CPython 3.8 ` asyncio ` . This
110
110
document identifies supported features. Except where stated program samples run
111
111
under MicroPython and CPython 3.8.
112
112
113
113
This tutorial aims to present a consistent programming style compatible with
114
114
CPython V3.8 and above.
115
115
116
- ## 0.1 Installing uasyncio on bare metal
116
+ ## 0.1 Installing uasyncio
117
117
118
- No installation is necessary if a daily build of firmware is installed or
119
- release build V1.13 or later. The version may be checked by issuing at
120
- the REPL:
118
+ Firmware builds after V1.13 incorporate ` uasyncio ` . The version may be checked
119
+ by issuing at the REPL:
121
120
``` python
122
121
import uasyncio
123
122
print (uasyncio.__version__ )
124
123
```
125
- Version 3 will print a version number. Older versions will throw an exception.
124
+ Version 3 will print a version number. Older versions will throw an exception:
125
+ installing updated firmware is highly recommended.
126
126
127
127
###### [ Main README] ( ../README.md )
128
128
@@ -143,11 +143,12 @@ The directory `primitives` contains a Python package containing the following:
143
143
* Additional Python primitives including an ISR-compatible version of ` Event `
144
144
and a software retriggerable delay class.
145
145
* Primitives for interfacing hardware. These comprise classes for debouncing
146
- switches and pushbuttonsand an asynchronous ADC class. These are documented
146
+ switches and pushbuttons and an asynchronous ADC class. These are documented
147
147
[ here] ( ./DRIVERS.md ) .
148
148
149
149
To install this Python package copy the ` primitives ` directory tree and its
150
- contents to your hardware's filesystem.
150
+ contents to your hardware's filesystem. There is no need to copy the ` tests `
151
+ subdirectory.
151
152
152
153
### 1.1.2 Demo programs
153
154
@@ -545,8 +546,8 @@ A further set of primitives for synchronising hardware are detailed in
545
546
To install the primitives, copy the ` primitives ` directory and contents to the
546
547
target. A primitive is loaded by issuing (for example):
547
548
``` python
548
- from primitives.semaphore import Semaphore, BoundedSemaphore
549
- from primitives.queue import Queue
549
+ from primitives import Semaphore, BoundedSemaphore
550
+ from primitives import Queue
550
551
```
551
552
When ` uasyncio ` acquires official versions of the CPython primitives the
552
553
invocation lines alone should be changed. e.g. :
@@ -715,7 +716,7 @@ evt2 = Event()
715
716
# Launch tasks that might trigger these events
716
717
evt = await WaitAny((evt1, evt2))
717
718
# One or other was triggered
718
- if evt == evt1:
719
+ if evt is evt1:
719
720
evt1.clear()
720
721
# evt1 was triggered
721
722
else :
@@ -909,7 +910,7 @@ following illustrates tasks accessing a resource one at a time:
909
910
910
911
``` python
911
912
import uasyncio as asyncio
912
- from primitives.semaphore import Semaphore
913
+ from primitives import Semaphore
913
914
914
915
async def foo (n , sema ):
915
916
print (' foo {} waiting for semaphore' .format(n))
@@ -973,7 +974,7 @@ Asynchronous methods:
973
974
974
975
``` python
975
976
import uasyncio as asyncio
976
- from primitives.queue import Queue
977
+ from primitives import Queue
977
978
978
979
async def slow_process ():
979
980
await asyncio.sleep(2 )
@@ -1132,7 +1133,7 @@ run at different speeds. The `Barrier` synchronises these loops. This can run
1132
1133
on a Pyboard.
1133
1134
``` python
1134
1135
import uasyncio as asyncio
1135
- from primitives.barrier import Barrier
1136
+ from primitives import Barrier
1136
1137
from machine import UART
1137
1138
import ujson
1138
1139
@@ -1259,7 +1260,7 @@ running. One second after the triggering ceases, the callback runs.
1259
1260
1260
1261
``` python
1261
1262
import uasyncio as asyncio
1262
- from primitives.delay_ms import Delay_ms
1263
+ from primitives import Delay_ms
1263
1264
1264
1265
async def my_app ():
1265
1266
d = Delay_ms(callback, (' Callback running' ,))
@@ -1283,7 +1284,7 @@ This example illustrates multiple tasks waiting on a `Delay_ms`. No callback is
1283
1284
used.
1284
1285
``` python
1285
1286
import uasyncio as asyncio
1286
- from primitives.delay_ms import Delay_ms
1287
+ from primitives import Delay_ms
1287
1288
1288
1289
async def foo (n , d ):
1289
1290
await d.wait()
@@ -1334,7 +1335,7 @@ using it:
1334
1335
1335
1336
``` python
1336
1337
import uasyncio as asyncio
1337
- from primitives.message import Message
1338
+ from primitives import Message
1338
1339
1339
1340
async def waiter (msg ):
1340
1341
print (' Waiting for message' )
@@ -1373,7 +1374,7 @@ Asynchronous Method:
1373
1374
1374
1375
The following example shows multiple tasks awaiting a ` Message ` .
1375
1376
``` python
1376
- from primitives.message import Message
1377
+ from primitives import Message
1377
1378
import uasyncio as asyncio
1378
1379
1379
1380
async def bar (msg , n ):
0 commit comments