0

Polling Rotary Encoder on 32u4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Polling Rotary Encoder on 32u4

by wb8nbs on Fri May 19, 2017 4:20 pm

Tried for about a day and a half to debounce a product 377 rotary encoder connected to a Feather. I finally found an example that uses a Gray code technique and works perfectly. It depended on using bits 0 and 1 of a port register though so for the Feather I had to modify slightly, the attached version uses bits 6 and 7 of port F on the 32u4 (Feather digital 18 and 19). The original example is at https://www.circuitsathome.com/mcu/read ... n-arduino/. Hope this helps someone.
Attachments
RotaryEncPoll2.zip
Example sketch for debounced rotary encoder
(917 Bytes) Downloaded 11 times

wb8nbs
 
Posts: 37
Joined: Sun May 29, 2011 9:54 pm

Re: Polling Rotary Encoder on 32u4

by adafruit_support_mike on Sat May 20, 2017 4:36 am

That's very interesting.. I wouldn't have though to read an encoder in terms of Gray code, but it makes perfect sense now that I've seen it.

Thanks for posting the link!

adafruit_support_mike
 
Posts: 45793
Joined: Thu Feb 11, 2010 2:51 pm

Re: Polling Rotary Encoder on 32u4

by adafruit_support_bill on Sat May 20, 2017 6:09 am

Very clever approach! Thanks for posting it.

adafruit_support_bill
 
Posts: 63405
Joined: Sat Feb 07, 2009 10:11 am

Re: Polling Rotary Encoder on 32u4

by wb8nbs on Sun May 21, 2017 10:23 pm

Oleg Mazurov also has a detailed post describing the same method but implemented with an interrupt routine. I couldn't use this because I already hacksawed off the end of the Feather that has the interrupt pins. https://www.circuitsathome.com/mcu/rotary-encoder-interrupt-service-routine-for-avr-micros/

wb8nbs
 
Posts: 37
Joined: Sun May 29, 2011 9:54 pm

Re: Polling Rotary Encoder on 32u4

by vibur on Sat Aug 05, 2017 2:45 pm

When I looked at this, I was getting four results with every turn of the encoder. How do you typically compensate for that? Sticking a /4 in various positions around the volume increment wasn't working for me.

vibur
 
Posts: 3
Joined: Thu Jun 22, 2017 11:33 pm

Re: Polling Rotary Encoder on 32u4

by wb8nbs on Sat Aug 05, 2017 7:13 pm

vibur wrote:When I looked at this, I was getting four results with every turn of the encoder. How do you typically compensate for that? Sticking a /4 in various positions around the volume increment wasn't working for me.


The function only returns +1 , -1 or zero. You can scale the result (volume) by dividing it by four.

wb8nbs
 
Posts: 37
Joined: Sun May 29, 2011 9:54 pm

Please be positive and constructive with your questions and comments.