Sparkfun Rotary encoder

Status
Not open for further replies.

pierrelenfestey

New member
Apologies if this is going over old ground. I'm a newbie with rotary encoders and I'm using the RGB encoder from Sparkfun (https://www.sparkfun.com/products/15141) with a Teensy 3.5

I'm getting weird readings form the encoder examples, both the "Basic" and "NoInterrupts" versions of the code. I'm eventually looking to use the encoder and Teensy to emulate a keyboard, so that I can program keystrokes into it and use it as an aid to shuttle backwards and forwards in an editing programme's timeline.

I have the encoder wired as follows:
Encoder pin A - pin13
Encoder Pin B - Pin14
Encoder Pin C (centre pin) - GND

and I'm getting the following on the serial monitor:
1
0
1
0
-1
0
1
0
-1
-2
-3
-4
-5
-6
-7
-8

The way these readings are generated are making me think that I've got the wiring wrong. When I rotate the encoder in one direction I get the reading alternating between 0 and 1 (or -1 depending on how I assign the pins in the code). When I rotate it in the other direction I usually get 4 numbers in quick succession incrementing in the opposite direction.

I've also tried adding 100nF caps between encoder pins A to GND and B to GND - same results

I've also tried using another encoder (same type) - same results.

I'm sure I'm doing something fundamentally wrong, but don't know what it is. I'm hoping it's something that will end with me face-palming :)

If you need me to post the code, I will, but it's the standard code from the Arduino Examples libraries.
 
Pin 13 has the LED, suggest using another pin as that may be complicating things.

If you do not have pullups set that can cause problems, but believe the library does that.

If problems are still around a test is to serial print the state of the two inputs once a second or so and slowly rotate it, watching for the OFF/ON sequence to step through.
 
That works now, but the position increments by 4 each time. I can adjust the code to execute one command every 4 steps, but it feels like the encoder should be able to increment the counter by one step - am I wrong?
 
Unfortunately it is pretty normal for encoders to have more than one step per click, no idea why. And just for extra challenge you may find that it is not an even four per click either.

Edit: data sheet looks to have 15 degrees per click, and 15 degrees for one full quadrature cycle (off and on for both contacts). Thinking about it, this may date to the days of electronic sensing of encoders rather than software, where the a rising edge on channel A would up or down count a counter IC based on the state of B channel, for one count per click. With software is easy to count both rising and falling edges and do so on both channels so we end up with more counts per click.
 
Last edited:
Status
Not open for further replies.
Back
Top