Rotary encoder.
Rotary encoder.
Warning Newbie alert!
Hi guys,
I want to use and ESP 32 as a wireless controller for film editing. I have micropython reading the states of the two pins but I lack the understanding of working out the logic of getting micropython to tell me which way the rotary encoder is turning.
I know there are 2 libraries available but I'm wondering if the authors are on this forum to explain to me how they work?
Please and thank you in advanced.
Hi guys,
I want to use and ESP 32 as a wireless controller for film editing. I have micropython reading the states of the two pins but I lack the understanding of working out the logic of getting micropython to tell me which way the rotary encoder is turning.
I know there are 2 libraries available but I'm wondering if the authors are on this forum to explain to me how they work?
Please and thank you in advanced.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: Rotary encoder.
I made a video to explain encoders and also in the second half of the video explain how code works to read them. https://www.youtube.com/watch?v=p4BCFhIuC88&t=6s
Software encoder counters usually peform baldy because of the speed the code needs to run at. I have used an external hardware counter chip with the ESP32 see https://www.youtube.com/watch?v=41ogu0UlwCc&t=78s
The STM32 MCUs have a hardware encoder counter as part of their timer peripherals
Software encoder counters usually peform baldy because of the speed the code needs to run at. I have used an external hardware counter chip with the ESP32 see https://www.youtube.com/watch?v=41ogu0UlwCc&t=78s
The STM32 MCUs have a hardware encoder counter as part of their timer peripherals
Re: Rotary encoder.
Stms?
Does that include the f103 aka the blue pill?
I'm starting to look at building around a stm
Does that include the f103 aka the blue pill?
I'm starting to look at building around a stm
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: Rotary encoder.
Yes bull pill does have endoser counters on their timers but the bluee pill doesn't have enough RAM or flash to run MicroPython.
If you use an official PyBoard then you will get the most amount of support.
Both the following boards are much less supported
If your super budget then these 2 new boards https://www.aliexpress.com/item/4000109 ... b201603_55 seen as the replacment for blue pill now known as the back pill have enough RAM and flash to run MP
This board https://www.aliexpress.com/item/4000602 ... b201603_53 has become my favorite STM32 board due to both price and it is capable of anything that I ever do.
If you use an official PyBoard then you will get the most amount of support.
Both the following boards are much less supported
If your super budget then these 2 new boards https://www.aliexpress.com/item/4000109 ... b201603_55 seen as the replacment for blue pill now known as the back pill have enough RAM and flash to run MP
This board https://www.aliexpress.com/item/4000602 ... b201603_53 has become my favorite STM32 board due to both price and it is capable of anything that I ever do.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Rotary encoder.
@AJB2K3 The encoder_portable solution should be about as fast as an interrupt driven pure MicroPython solution can be. It certainly won't match hardware solutions, but even on sluggish platforms like ESPx it should handle up to ~1K edges/sec.
Code: Select all
import time
from machine import Pin
from encoder_portable import Encoder
phase = Pin(0, Pin.IN, Pin.PULL_UP) # Change the 1st arg to match hardware
quad = Pin(2, Pin.IN, Pin.PULL_UP)
e = Encoder(phase, quad, False, 1)
while True:
print(e.position)
time.sleep(1)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Rotary encoder.
Hello,
There is a PR pending to add hardware counter device support of the ESP32 to micropython:
https://github.com/micropython/micropython/pull/5496
Your post show that there is interest in hardware counter with esp32.
There is a PR pending to add hardware counter device support of the ESP32 to micropython:
https://github.com/micropython/micropython/pull/5496
Your post show that there is interest in hardware counter with esp32.
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016
micropython firmware Daily build 05/31/2016
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Rotary encoder.
The docs - ESP32 notes indicate that modes capable of handling encoders exist but are unsupported in this PR.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: Rotary encoder.
Has anyone here personally used the PCNT peripheral to count Quadrature encoders????
By reading the Espressif docs it is clear that the PCNT will read a single encoder but when reading the docs the second channel of the PCNT doesn't work like a quadrature encoder but rather the second channel is a direction channel and depending upon whether it it is low or high whether the counter counts up or down.
I have never used the PCNT because reading the docs it doesn't appear it can count quadrature encoders, I have used software, a hardware IC (LS7366R) and the hardware quadrature counter on the timers of the STM32 to count quadrature encoders.
I would be super interested to hear from anyone that has personally tried to use PCNT to count quadrature encoders and can confirm if it does work or doesn't work
By reading the Espressif docs it is clear that the PCNT will read a single encoder but when reading the docs the second channel of the PCNT doesn't work like a quadrature encoder but rather the second channel is a direction channel and depending upon whether it it is low or high whether the counter counts up or down.
I have never used the PCNT because reading the docs it doesn't appear it can count quadrature encoders, I have used software, a hardware IC (LS7366R) and the hardware quadrature counter on the timers of the STM32 to count quadrature encoders.
I would be super interested to hear from anyone that has personally tried to use PCNT to count quadrature encoders and can confirm if it does work or doesn't work
Re: Rotary encoder.
Hello,
think this theme is almost solved, please see:
viewtopic.php?f=18&t=5997&p=43919&hilit ... ngp#p43919
And follow the links.
Problem is: MicroPython is slow and you may not guarantee a suitable minimal cycle time which is necessary when using software solutions. So the only way is using hardware - but good news: this hardware exists on ESP32, even for multiple channels!
Best regards,
Peter
think this theme is almost solved, please see:
viewtopic.php?f=18&t=5997&p=43919&hilit ... ngp#p43919
And follow the links.
Problem is: MicroPython is slow and you may not guarantee a suitable minimal cycle time which is necessary when using software solutions. So the only way is using hardware - but good news: this hardware exists on ESP32, even for multiple channels!
Best regards,
Peter