guild icon
Toit
#GPIO interrupts?
Thread channel in help
AbedN
AbedN 05/15/2025 12:47 PM
Hi,
I'm trying to configure one of the ESP32C6 GPIOs as an interrupt pin recieving signal from an external sensor and acting accordingly as per some routine which should run simultaneously with the rest of the program. any ideas/workarounds?
AbedNOPAbedN
Hi, I'm trying to configure one of the ESP32C6 GPIOs as an interrupt pin recieving signal from an external sensor and acting accordingly as per some routine which should run simult...
floitsch
floitsch 05/15/2025 01:05 PM
In Toit we typically do pin.wait-for x the value we are waiting for.
Under the hood, Toit creates an interrupt and listens for the change. In the Toit layer the currently running task is suspended and will be woken up once the signal from the lower layer is received.
If you want to do other work in the meantime you use task to create another cooperative task. Whether the code that waits for the pin or whether the other code is in a task depends on your program.
floitsch
floitsch 05/15/2025 01:07 PM
Example:
import gpio main: pin := gpio.Pin 32 --input --pull-up task:: while true: pin.wait-for 0 print "Got pulled to ground" sleep --ms=200 // Debounce. pin.wait-for 1 sleep --ms=200 // Debounce. while true: print "In main-loop" // Let other tasks run. // The 'sleep' function automatically yields. Otherwise a call to 'yield' would // also give other tasks a chance to run. sleep --ms=1_000
👍1
3 messages in total