MicroPython quadrature incremental encoder based on machine.Pin() interrupts.
It uses Quadrature decoder state table and state transitions.
Applicable for hand-driven devices like
See also encoder problems and code samples at Incremental encoders by Peter Hinch.
The internal mechanical operation of a mechanical encoder produces a lot of switch bouncing which is surpressed with a low-pass filters (formed by a 10kΩ and 0.1µF).
See also manufacturer recommendation Bourns_enc_sgnl_cond_technote.pdf
Minimal example:
from machine import Pin
from encoder_state import Encoder
enc = Encoder(Pin(1), Pin(2))
value = enc.value()
while True:
val = enc.value()
if value != val:
value = val
print(value)
Quick start:
- Connect encoder to the MicroPython board.
- Upload the encoder_state.py to the board.
- Run the encoders_test.py
Tested on ESP32 board.
Needs to be tested on other MicroPython boards.