← index #5214PR #8766
Related · high · value 2.767
QUERY · ISSUE

pulse counter quadrature encoder

openby ZeshuiLiopened 2019-10-15updated 2025-10-03
enhancement

How can I use this firmware to get the output of the quadrature encoder

CANDIDATE · PULL REQUEST

ESP32: Add Quadrature Encoder and Pulse Counter classes.

openby IhorNehrutsaopened 2022-06-16updated 2025-08-13
port-esp32

Applied to industrial encoders. Has a 32-bit wide counter!!! Has a 32-bit wide matching value !!! (64 bit wide is possible).
image

Count pulses on Pin(17) with direction on Pin(16) an irq handler on zero value.

from machine import Counter, Pin

def irq_handler(self):
    print('irq_handler()', self.id(), self.status(), self.value())

cnt = Counter(0, src=Pin(17, mode=Pin.IN), direction=Pin(16, mode=Pin.IN))
cnt.irq(irq_handler, Counter.IRQ_ZERO)  # set irq handler
print(cnt.value())  # get current counter value

Please note that this pull request
ESP32: Add Quadrature Encoder and Pulse Counter classes. #8766
and
docs\machine: Add Counter and Encoder classes. #8072
and
mimxrt: Add Quadrature Encoder and Pulse Counter classes. #7911
are mutually agreed upon.

Note: MicroPython-lib PR Add Stepper Motor PWM-Counter driver. requires this PR.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied