asyncio_serial for ESP32 #10753
Unanswered
garykuipers
asked this question in
ESP32
Replies: 3 comments 1 reply
-
Thank you Peter: I am halfway there: The transmit works, the receive does
not work for me. Here is what I am testing. The three calls to
swrite.writer work. The state of the device I am communicating with changes
in accordance to what would be expected when the messages are received.
There is no response. As always, guidance is appreciated.
The program:# Test of uasyncio stream I/O using UART
# Author: Peter Hinch
# Copyright Peter Hinch 2017-2022 Released under the MIT license
# Link X1 and X2 to test.
import uasyncio as asyncio
from machine import UART
uart = UART(2, 9600, timeout=0) # these are TX2(GPIO17) and RX2(GPIO16)
async def sender():
swriter = asyncio.StreamWriter(uart, {})
print('started sender loop')
while True:
ascii = "find\r"
print(f'writing >>>{ascii}<<<\n ')
swriter.write(ascii)
await swriter.drain()
await asyncio.sleep(10)
ascii = 'X'
print(f'writing >>>{ascii}<<<\n ')
swriter.write(ascii)
await swriter.drain()
await asyncio.sleep(10)
ascii = "c,1\r"
print(f'writing >>>{ascii}<<<\n ')
swriter.write(ascii)
await swriter.drain()
await asyncio.sleep(10)
async def receiver():
sreader = asyncio.StreamReader(uart)
print('started receiver loop')
while True:
print('waiting on receive')
res = await sreader.readline()
print('Received', res)
async def main():
asyncio.create_task(sender())
asyncio.create_task(receiver())
while True:
await asyncio.sleep(1)
def test():
try:
asyncio.run(main())
except KeyboardInterrupt:
print('Interrupted')
finally:
asyncio.new_event_loop()
print('as_demos.auart.test() to run again.')
test()
# The table below specifies the RX and TX pins for each of the three UART
ports available in ESP32.
# UART TX/RX Rx Tx Useable
# UART0 0 GPIO3 GPIO1 Yes
# UART1 GPIO9 GPIO10 Yes but requires the reassignment of pins
# UART2 2 GPIO16 GPIO17 Yes
The log produced:
MPY: soft reboot
started sender loop
<<<ting >>>find
started receiver loop
waiting on receive
writing >>>X<<<
<<<ting >>>c,1
<<<ting >>>find
writing >>>X<<<
Interrupted
…On Wed, Feb 15, 2023 at 6:24 AM Peter Hinch ***@***.***> wrote:
Also here
<https://github.com/peterhinch/micropython-async/blob/master/v3/docs/TUTORIAL.md#63-using-the-stream-mechanism>
.
—
Reply to this email directly, view it on GitHub
<#10753 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEVW4EOWKFUHGHIFI2IAQ7DWXS4HJANCNFSM6AAAAAAU3X554Y>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
--
Gary Kuipers, President, Casinfo
cell +1 805 443 9446 other +1 702 608 6558
|
Beta Was this translation helpful? Give feedback.
0 replies
-
The use of <<<ting >>>find which had me puzzled for a moment, but the code is behaving correctly. I can see no reason for the receiver failing and I suspect a hardware problem. If you have access to a scope or LA I would check that data is actually being received. Alternatively do the classic loopback test: link |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Two questions:
1)Searches in google about asyncio serial tends to give examples with "import_asyncio_serial", but it is not installable via upip.install. Can someone point me at where I can find this module?
Beta Was this translation helpful? Give feedback.
All reactions