guild icon
Toit
#interrupts
Thread channel in help
Macca
Macca 04/18/2023 07:01 AM
Hi all, I am trying to implement interrupts on the A and B pins of a rotary encoder. I can't find any documentation on this, help please.
MaccaOPMacca
Hi all, I am trying to implement interrupts on the A and B pins of a rotary encoder. I can't find any documentation on this, help please.
floitsch
floitsch 04/18/2023 07:44 AM
Toit doesn't give direct access to interrupts. If you just want to wait for a pin to change you would generally use pin.wait_for. However, for a rotary encoder that would probably be too slow.
I think the pulse_counter library is what you are looking for: https://libs.toit.io/pulse_counter/library-summary
floitsch
floitsch 04/18/2023 07:47 AM
That peripheral automatically counts pulses for you. I'm not too familiar with rotary encoders, though. So maybe that doesn't work.
Macca
Macca 04/18/2023 07:50 AM
Mmm, rotary encoders rely on the relationship of Pin A and Pin B. There are usually four possible stable states. which indicate the direction of rotation.
Macca
Macca 04/18/2023 07:50 AM
I will try the pulse counter as I have an upcoming project anyway.
floitsch
floitsch 04/18/2023 07:50 AM
The pulse counter has one pin to count and another as control pin for the direction.
Macca
Macca 04/18/2023 07:51 AM
Ok, that may work, i'll investigate.
👍1
aschober
aschober 04/27/2025 05:27 AM
two years later -- but in case it's helpful, I implemented an algorithm for a rotary encoder using a pulse counter:
https://github.com/aschober/toit-m5stack-dial/blob/260e496420361ef2f15b6247567bffbabfc3b913/src/m5stack_dial.toit#L166-L226
Toit driver for the M5Stack M5Dial. Contribute to aschober/toit-m5stack-dial development by creating an account on GitHub.
kaxori
kaxori 04/28/2025 06:03 PM
:👌🏻: Thank you
9 messages in total