Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Sparkfun Rotary encoder

  1. #1

    Sparkfun Rotary encoder

    Apologies if this is going over old ground. I'm a newbie with rotary encoders and I'm using the RGB encoder from Sparkfun ( 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:

    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.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    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.

  3. #3
    Thanks very much, I'll get on it and post the result.

  4. #4
    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?

  5. #5
    Senior Member
    Join Date
    Apr 2013
    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 by GremlinWrangler; 09-19-2019 at 01:12 PM. Reason: Checked data sheet

  6. #6
    Well, I can't thank you enough.

    Although I did just notice the advice in the notes on the code - don't use a pin with and LED. Duh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts