Uasyncio basics

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Delebel
Posts: 48
Joined: Thu May 25, 2017 2:21 pm
Contact:

Uasyncio basics

Post by Delebel » Thu Jun 02, 2022 12:57 pm

I'm attempting to use asyncio as described in the tutorial on Github and the flashing led example runs fine. However as stated once a asycncio.run() is issued no other processing occurs. In my specific application I want 4 DHT22 sensors to be read one per second so every 4 seconds all the readings would be available for the application. I can read the DHT sensors fine in synchronous mode and converted the code to run asynchronous and that works. However the rest of the user interactive code (to handle buttons and other user actions) can never run as stated in the tutorial. Therefore am I correct in assuming I MUST include the user interactive processing code as a task in the uasyncio.run() loop and should it be as async def foo()s or can it be synchronous code that is give processing time by the uasyncio.run() loop?

Regards Denis

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Uasyncio basics

Post by pythoncoder » Sat Jun 04, 2022 9:32 am

See this doc which describes classes for interfacing switches and pushbuttons. Using these, switch status changes can run callbacks.
Peter Hinch
Index to my micropython libraries.

Post Reply