Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Re: learning about asyncio with rotary encoder

$
0
0
Mixing async with sync code is not simple. One solution is to switch from using asyncio to using threads.

Assuming you want to stay with asyncio, perhaps the simplest solution is to create an async function that continuously polls the input pin instead of using GPIO.add_event_detect. You can create an asyncio task to run this continuously without constantly calling the function from within your code.

To use GPIO.add_event_detect, you may be able to do so using an asyncio future. I did this to receive input from Pyserial, which is not asyncio. An example of this may be seen here https://github.com/MrYsLab/telemetrix-a ... al.py#L112

Statistics: Posted by MrYsLab — Mon Jan 27, 2025 3:31 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles