Rotary encoder with interrupt capability for Teensy 2.0++

8 replies · 3K views · last reply
shushi_boi
Messages
44
Reaction score
0
In this project,
https://bitbucket.org/selectnone/ra...ls.ino?at=master&fileviewer=file-view-default

14 // Change these pin numbers to the pins connected to your encoder.
15 // Best Performance: both pins have interrupt capability1Q
16 // Good Performance: only the first pin has interrupt capability
17 // Low Performance: neither pin has interrupt capability
18 Encoder knobEnc(0, 1);
19 Encoder scrollEnc(2, 3);
20 int encoderPins[] = {2,3,4,5,};
21 // (avoid using pins with LEDs attached)​

It states that a rotary encoder with "interrupt capabilities" is recommended for this project (which connects to the Teensy 2.0++ pins, which the Teensy connects to the Raspberry Pi 2 via usb)

Labelled pinout diagram of a Teensy 2.0++ board, listing digital pin numbers with PWM, INT and analog (A0 to A7) functions, plus GND, +5V, RST and AREF pins.


I'm guessing that interrupt capabilities are knobs that also act like pushbuttons, in the same way that car radio volume control knobs are (which you can push like buttons) "...the knob also acts as a pushbutton which sends an interrupt to your target board\'s MCU."

in

https://bitbucket.org/selectnone/raspipboy/wiki/Controls.md

He states that the rotary encoder's knob should also act like a push button, so that it's a mouse that alternates between diagnal and horizontal movements.

•Move Map Cursor
○Mouse Move
(Knob on back of hand: rotational encoder with switch - alternates between X/Y movement when pushed down)​
 
billy_joule said:
An interrupt occurs within the software.

https://en.m.wikipedia.org/wiki/Interrupt
They can be triggered by many different ways, including a simple switch.
You want a rotary encoder with a push button, something like this;
https://www.adafruit.com/product/377

I appreciate your insightful response and for your clarification, thank you Billy! I've got one more question, since this switch encoder has 6 pins and the Teensy needs to connect to it through these 6 pins (0, 1, 2, 3, 4, 5),

is

Encoder knobEnc(0, 1);​

just the pins for the knob when the switch is not pressed on the encoder,

Encoder scrollEnc(2, 3);​

pins where the knob is pressed down, and

int encoderPins[] = {2,3,4,5,};​

are the the remaining pins which would be used for the interrupt features?
 
One side of the switch and the common pin of the encoder are usually connected to ground. Also one of the pins is clipped short and has no documented function. If I had to guess it is connected to the encoder common. It might also not be connected at all. It is removed during manufacture to add polarization to the part. Just ignore it.

So now you have three signals. At minimum you will want an interrupt on the two encoder signals. The switch function would be wired up however is most convenient. Either interrupt or polled should be adequate.

BoB
 
  • Like
Likes   Reactions: shushi_boi
rbelli1 said:
One side of the switch and the common pin of the encoder are usually connected to ground. Also one of the pins is clipped short and has no documented function. If I had to guess it is connected to the encoder common. It might also not be connected at all. It is removed during manufacture to add polarization to the part. Just ignore it.

So now you have three signals. At minimum you will want an interrupt on the two encoder signals. The switch function would be wired up however is most convenient. Either interrupt or polled should be adequate.

BoB

I appreciate your Help rbelli1!

After building this circuit based off of Neal Corbett's [the guy who created the Raspberry Pip Boy project alongside Grieve] posts and videos
http://blog.obliviongizmo.com/



Four-panel video screenshot of a Raspberry Pi Pip-Boy build showing a tangle of red and yellow jumper wires connected to a green circuit board and a small red-and-white component.


Wiring schematic of a Teensy 2.0++ microcontroller board with a rotary switch, rotary encoders, tact switches, LED-resistor pairs, a battery voltage divider, a 1N4001 diode and USB and audio connectors.


I've got confused with pins 4 and 5 found here

Screenshot of Teensy 2++ Arduino source code with a Controls panel overlay listing Pip-Boy key bindings, with underlined pin definitions for encoders, battery voltage divider and temperature sensor.

*Highlighted in red are the pins and circuit that I don't understand, which are 4, 5 (or rotary encoder) and how to wire the voltage divider battery pins 44, & 38

My personal setup is a little different from his and I won't include the temperature sensor nor the radiation-gauge running off of a stepper motor (I will add a real one, similar to some of the ideas from this NASA Pip Boy xD :DD)
https://2014.spaceappschallenge.org/project/pip-boy-3000/

Pictures of my personal setup are down bellow, but they are subject to change.

So primarily, how would I wire pins 4 and 5 to the rotary encoders? Are they pins or are they just numbers? :confused:

If possible too, how do I wire together the voltage divider circuit?

Thank you for your guy's time and I hope that these schematics may help others too if they are interested in this project! :biggrin:

Wiring schematic of a Pip Boy style device showing a Raspberry Pi processor, Geiger counter, LED strip, rotary encoders, voltage divider and battery connections, with a Teensy CC2650 sensor tag and power regulators.

*my own set-up which is not the traditional Pip Boy 3000, it's my own modern and functional version, I plan on adding wearable technology in the glove and inside the Pip Boy to add more information about the environment, your own vitals and tools to help you out

Collage of concept renders of a Fallout Pip-Boy wrist device and gauntlet, including a green-screen Pip-Boy display showing a vault-boy figure, a bare wrist unit, and a glove with a dark fabric sleeve, plus game cartridges and headphones.

*An old visual representation of how I plan to put together my own set-up
 
shushi_boi said:
So primarily, how would I wire pins 4 and 5 to the rotary encoders? Are they pins or are they just numbers?

The pin numbers are all port designations per the CPU datasheet. D4 and D5 are port D bits 4 and 5. To connect them to the encoder you put a resistor of the appropriate value from each pin to VCC and usually a capacitor from the pin to ground. The resistor by convention is 10K and you need to select a capacitor to make the rise time slow enough so as to filter out switch bounce but also fast enough to allow the encoder to work fast enough. Connect these inputs to the two encoder output pins and the common to ground.

The battery voltage divider appears to be measuring an approximation of VCC through a port pin. If you are using some other battery power source you will want to connect to that voltage. Use higher values of resistor to minimize current draw.BoB
 
  • Like
Likes   Reactions: shushi_boi
Thank you rbelli1 for your help again!

rbelli1 said:
To connect them to the encoder you put a resistor of the appropriate value from each pin to VCC and usually a capacitor from the pin to ground... Connect these inputs to the two encoder output pins and the common to ground.

So to make sure I understand you correctly, is this correct the way I have it wired up, or when you say "encoder output pins" do you mean all the pins except the common ground pins?

Wiring schematic of a Teensy++ board with two rotary encoders for mouse move and scroll-wheel keys, showing 5V, resistor, capacitor and ground connections to digital pins D0 through D5.

*the diodes I used have a voltage drop of 0.6 volts and are called 1N4001*

And for the capacitor ratings, which one would you suggest I use? In terms of voltage, frequency etc.?

Thank you again for your help valuable help !
 
I apologize for the bad drawing, I fixed it a little better.
Wiring schematic of a Teensy++ 2.0 board (AT90USB1286) with a USB connector, 16 MHz crystal and 10kΩ pull-down resistor, plus two rotary encoders labelled Mouse Move Knob and Scroll-wheel Up/Down, each with A and B pins wired to Teensy pins D0 to D3 through debounce resistors and capacitors to +5V and ground.


I'm not sure if just the B is the output pin of both encoders or its both A and B.
 
Here, I drew out other ways I think it could be wired.

Wiring schematic of a Teensy++ 2.0 board with two rotary encoders (Mouse Move Knob and Scroll-wheel) connected to digital pins D0 to D5, with a 10K pull-down resistor on the right and a note about debouncing with 5V, resistor, encoder, and capacitor to ground.

(I feel like its most likely this one, because Pin D4 would correspond to both outputs (A & B) Pins of one encoder, and Pin D5 the other output of the other encoder)

Wiring schematic of a Teensy++ board with two rotary encoders, Mouse Move Knob and Scroll-wheel, connected to pins D0 to D5 and a 10K pull-up resistor, with a debounce note reading 'To debounce the circuit +5v -> resistor -> encoder + arduino -> capacitor -> ground'.

(The thought behind this one is that D4 focuses on the output of one of the Pins from both encoders whereas D5 focuses on one of the output pins from both of the other encoders)
Wiring schematic of a Teensy++ board with two rotary encoders, labelled Mouse Move Knob and Scroll-wheel, connected to output pins D0 to D7 with pull-up resistors and debounce capacitors.

(Where I connect D4 and D5 to all of the output pins)

I apologize for all of the confusion, I still consider myself new to electronics :P