Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.49 KB

File metadata and controls

37 lines (27 loc) · 1.49 KB

MicroPython quadrature incremental encoder

MicroPython quadrature incremental encoder based on machine.Pin() interrupts.
It uses Quadrature decoder state table and state transitions.

Applicable for hand-driven devices like

image

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).
image
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.