Hi Oli,
This is a hidden and not officially documented functionality included some years ago only for the classic ESP32. It was never completed, and I even forgot about it until this subject came to light recently.
Incidentally, it also seems to work for the ESP32-S3, but I've never tested it. Following your feedback, it appears there's a problem with how the internal interrupt is handled when the PCNT counter overruns.
Under the hood, I'm using the library https://github.com/madhephaestus/ESP32Encoder, which was recently updated, so support for the ESP32-S2 could be possible.
As soon as I have the chance to look into it, I'll see what can be done.
Reading a rotary encoder
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
- Oli
- Posts: 116
- Joined: Tue Feb 09, 2021 10:07 am
- Location: Germany, Meissen
- Has thanked: 34 times
- Been thanked: 66 times
- Contact:
Re: Reading a rotary encoder
i can't do anything with the library, i can't mix c with basic. i'm already happy with the implementation,
with esp32 and esp32s3 it already works.
with 4-fold super,
with 2-fold i couldn't find any errors yet.
with 1-fold it counts unreliably.
but the counter overflow, it shouldn't crash.
if it skips to -16 bit I could evaluate it somehow,
it would be great if an interupt jump would take place, which would calculate the 15 bits for me mathematically,
I think you understand what I mean, for the servo motor I have to calculate the encoder and the clock direction signal against each other and with PID to the PWM for the motor,
Translated with DeepL.com (free version)
with esp32 and esp32s3 it already works.
with 4-fold super,
with 2-fold i couldn't find any errors yet.
with 1-fold it counts unreliably.
but the counter overflow, it shouldn't crash.
if it skips to -16 bit I could evaluate it somehow,
it would be great if an interupt jump would take place, which would calculate the 15 bits for me mathematically,
I think you understand what I mean, for the servo motor I have to calculate the encoder and the clock direction signal against each other and with PID to the PWM for the motor,
Translated with DeepL.com (free version)
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
Re: Reading a rotary encoder
I've just updated the version 2.00.95 that fixes this issue.
Additionally I included a extra function
WLOG ENCODER.SETFILTER value
that filters against rebounds (more details here)
Let me know if it works for you
Additionally I included a extra function
WLOG ENCODER.SETFILTER value
that filters against rebounds (more details here)
Let me know if it works for you
- Oli
- Posts: 116
- Joined: Tue Feb 09, 2021 10:07 am
- Location: Germany, Meissen
- Has thanked: 34 times
- Been thanked: 66 times
- Contact:
Re: Reading a rotary encoder
oh, how can i thank you for responding so quickly in this weather.
i was able to test it on the ESP32S2, it works.
I didn't notice much with the filter, it makes no difference in my case, the signals from the encoder are perfect.
with 1-fold it makes the same errors, but that's normal, if one edge changes back and forth, the other remains is counted and not back. 2-fold and 4-fold work.
the counter without problems over the 32000, your background is mysticism
I have had the motor counted up to 11,000,000 = 11 million and back, no loss of steps. (4-steps) I have no idea how far it can go 
when i restart the program, the counter is not 0
your correction value -15 bit. wlog ENCODER.RESET at the beginning of the program solves this.
my modules have only 4MB i can't test the ESP32S3.
in this secound i found 2.00.95 BLE_CAN_DMT_HID_OTG_qio_opi 2,327,120 i test now, sorry bootloop
i don't need an OTA, is there a way to free up space ?
is there a way to use AnnexToolKit with the new partition table ? the webflasher is great, but i don't always have internet,
best regards Oli
i was able to test it on the ESP32S2, it works.
I didn't notice much with the filter, it makes no difference in my case, the signals from the encoder are perfect.
with 1-fold it makes the same errors, but that's normal, if one edge changes back and forth, the other remains is counted and not back. 2-fold and 4-fold work.
the counter without problems over the 32000, your background is mysticism


when i restart the program, the counter is not 0
your correction value -15 bit. wlog ENCODER.RESET at the beginning of the program solves this.
my modules have only 4MB i can't test the ESP32S3.
in this secound i found 2.00.95 BLE_CAN_DMT_HID_OTG_qio_opi 2,327,120 i test now, sorry bootloop
i don't need an OTA, is there a way to free up space ?
is there a way to use AnnexToolKit with the new partition table ? the webflasher is great, but i don't always have internet,
best regards Oli
Code: [Local Link Removed for Guests]
total_counter = 0
last_display_counter = 0
PIN.MODE 5, INPUT, PULLUP ' Pin A (CLK)
PIN.MODE 6, INPUT, PULLUP ' Pin B (DT)
wlog ENCODER.SETUP 5, 6, 2 ' Modus 2 = 4-fach Auswertung
wlog ENCODER.RESET
'WLOG ENCODER.SETFILTER 400
' Hauptschleife
DO
display_counter = ENCODER.COUNT ' Zählerstand lesen
IF display_counter <> last_display_counter THEN
wlog "Position: "; display_counter
last_display_counter = display_counter
ENDIF
PAUSE 60
LOOP
You do not have the required permissions to view the files attached to this post.
Last edited by Oli on Sun Jul 06, 2025 2:20 pm, edited 2 times in total.
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
Re: Reading a rotary encoder
I've just uploaded a version without LVGL that should fit in your module.
The counter is 64 bits so I think that it will be difficult to reach the end value
The AnnexToolkit is not supported anymore and I do not encourage to use it as it is much easier for me to update the online flasher than update the toolkit.
Last but not the least, Yes, it is possible to change the partition table, but it something advanced that I do not support (maybe in the future)
The counter is 64 bits so I think that it will be difficult to reach the end value

The AnnexToolkit is not supported anymore and I do not encourage to use it as it is much easier for me to update the online flasher than update the toolkit.
Last but not the least, Yes, it is possible to change the partition table, but it something advanced that I do not support (maybe in the future)
- Oli
- Posts: 116
- Joined: Tue Feb 09, 2021 10:07 am
- Location: Germany, Meissen
- Has thanked: 34 times
- Been thanked: 66 times
- Contact:
Re: Reading a rotary encoder
in this secound i found 2.00.95 BLE_CAN_DMT_HID_OTG_qio_opi 2,327,120 , sorry bootloop
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
- Oli
- Posts: 116
- Joined: Tue Feb 09, 2021 10:07 am
- Location: Germany, Meissen
- Has thanked: 34 times
- Been thanked: 66 times
- Contact:
Re: Reading a rotary encoder
2.00.92 CAN_DMT_HID_OTG_qio_opi 2,144,752 is running well,
https://www.waveshare.com/esp32-s3-zero.htm
https://www.waveshare.com/esp32-s3-zero.htm
- cicciocb
- Site Admin
- Posts: 3254
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 650 times
- Been thanked: 2290 times
- Contact:
- Oli
- Posts: 116
- Joined: Tue Feb 09, 2021 10:07 am
- Location: Germany, Meissen
- Has thanked: 34 times
- Been thanked: 66 times
- Contact:
Re: Reading a rotary encoder
Annex32-S3 CAN USB DMT HID OTG 2.00.92 qio qspi is working
i try another module also, an erase flash bevore
qio qspi is working,
I don't know why the other one qio_opi worked before,
thy 2.00.95 qio qspi
best regards Oli
i try another module also, an erase flash bevore
qio qspi is working,
I don't know why the other one qio_opi worked before,
thy 2.00.95 qio qspi
best regards Oli
You do not have the required permissions to view the files attached to this post.