Asyncio: Polling + ISR's... Bad combination #11427
Replies: 3 comments 19 replies
-
https://github.com/peterhinch/micropython-async/blob/master/v3/docs/INTERRUPTS.md |
Beta Was this translation helpful? Give feedback.
-
This has no relationship with asyncio. The Don't use global variables to communicate events between ISR and main loop. The ThreadSafeFlag has been specifically designed to do that signaling safely as described in the links provided above by @dlech. Please see the examples there. Just curiosity: What is the reaction time you need for the interrupt? |
Beta Was this translation helpful? Give feedback.
-
Just to clarify: "Polling a device" means a code like this: while True:
while pin.value()==0:
await asyncio.sleep_ms( 100 )
... Do something because the signal went from 0 to 1
while pin.value()==1:
await asyncio.sleep_ms( 100 ) No ISR is needed when polling. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everybody!
I've been reading that is not recommended to use ISR interruptions in general when you are using asyncio, for multiple important reasons... (some of them I understand, others not. I'm a junior junior programmer, sorry). but I thought that it would be very usefull in some simple cases with a just little bit of code in specific cases. For example:
Executing this code (synchronous, without asyncio):
is completly fine and it works.
But using the same strategy inside a task/coro doesn't work:
The scope of "a boolean" variable is never global, so "a boolean" always is False and we don't come into "if". What I'm doing wrong?? Maybe this is one important reason for not use this mix: asyncio + isr? Is there a solution?
Thank you very much.
Beta Was this translation helpful? Give feedback.
All reactions