|
1 | 1 | # asyntest.py Test/demo of asychronous use of MessagePack
|
2 | 2 |
|
3 |
| -# Configured for a Pyboard. Link pins X1 and X2. |
4 |
| - |
5 | 3 | # Copyright (c) 2021 Peter Hinch Released under the MIT License see LICENSE
|
6 | 4 |
|
7 |
| -# Free RAM after reset 101504 bytes. Free RAM while running 82944 bytes |
8 |
| -# Usage 18560 bytes i.e. ~18.1KiB |
9 |
| -# This compares with 5312 bytes for a similar script sending plain text. |
10 |
| -# The MessagePack overhead is thus 13,248 bytes (12.9KiB). |
| 5 | +# From testing on a pyboard: |
| 6 | +# Free RAM after reset 101504 bytes. Free RAM while running 82944 bytes |
| 7 | +# Usage 18560 bytes i.e. ~18.1KiB |
| 8 | +# This compares with 5312 bytes for a similar script sending plain text. |
| 9 | +# The MessagePack overhead is thus 13,248 bytes (12.9KiB). |
11 | 10 |
|
| 11 | +from sys import platform |
12 | 12 | import asyncio
|
13 | 13 | import umsgpack
|
14 | 14 | from machine import UART, Pin
|
15 | 15 | import gc
|
16 | 16 |
|
17 |
| -try: |
| 17 | + |
| 18 | +if platform == "pyboard": |
18 | 19 | uart = UART(4, 9600) # Pyboard (link pins X1 and X2)
|
19 |
| -except ValueError: |
| 20 | +elif platform == "rp2": |
20 | 21 | uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1)) # Pi Pico (link pins 0 and 1)
|
| 22 | +elif platform == "esp32": |
| 23 | + uart = UART(2, baudrate=9600, tx=17, rx=16) # Adafruit Huzzah32 (link pins TX and RX) |
| 24 | +else: |
| 25 | + raise OSError(f"Unknown platform {platform}") |
| 26 | + |
21 | 27 |
|
22 | 28 | async def sender():
|
23 | 29 | swriter = asyncio.StreamWriter(uart, {})
|
|
0 commit comments