geekhack
geekhack Projects => Making Stuff Together! => Topic started by: popcap on Wed, 28 August 2019, 21:13:27
-
If this isn't in the right place please let me know.
I am looking for a resource to figure out how to add a rotary encoder into my pcb design. I am using a atmega32u2.
Any help would be greatly appreciated.
-
A rotary encoder is just like a set of switches that activate in the order of Gray code (https://en.wikipedia.org/wiki/Gray_code) when turned. However, like other switches, input needs to be debounced.
Most encoders for user input have three pins and produces a 2-bit Gray code. Keebio and others sell the EC11 (https://keeb.io/collections/split-keyboard-parts/products/rotary-encoder-ec11?variant=15982789394526), so I would support that if I was designing a PCB to sell.
You could just connect common to GND, and input pins directly to GPIO pins on the AVR (with internal pull-ups enabled) with your firmware polling the encoder every ms and debounce in software.
You could even put a rotary encoder as part of a keyboard matrix, with the common pin on a column (shorted to GND when strobed), and each input pin on a row — if the necessary debouncing time is not longer than for the key switches.
Do consult the encoder's datasheet and examples in the firmware you intend to use.
The alternative would be to debounce each pin in hardware. In this case, your firmware could be based on pin-change interrupts, and you would have to use a pin from port B. Debounce the same way as for switches.
-
A rotary encoder is just like a set of switches that activate in the order of Gray code (https://en.wikipedia.org/wiki/Gray_code) when turned. However, like other switches, input needs to be debounced.
Most encoders for user input have three pins and produces a 2-bit Gray code. Keebio and others sell the EC11 (https://keeb.io/collections/split-keyboard-parts/products/rotary-encoder-ec11?variant=15982789394526), so I would support that if I was designing a PCB to sell.
You could just connect common to GND, and input pins directly to GPIO pins on the AVR (with internal pull-ups enabled) with your firmware polling the encoder every ms and debounce in software.
You could even put a rotary encoder as part of a keyboard matrix, with the common pin on a column (shorted to GND when strobed), and each input pin on a row — if the necessary debouncing time is not longer than for the key switches.
Do consult the encoder's datasheet and examples in the firmware you intend to use.
The alternative would be to debounce each pin in hardware. In this case, your firmware could be based on pin-change interrupts, and you would have to use a pin from port B. Debounce the same way as for switches.
Thank you for this definitely putting me down the right path in figuring this out.
-
The folks who make the Teensy have a library available and some examples here (https://www.pjrc.com/teensy/td_libs_Encoder.html).