Skip to content

IhorNehrutsa/MicroPython-quadrature-incremental-encoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Interrupt based MicroPython quadrature incremental encoder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages