RGB Led Rotary Encoder Pin Out

Hi, Im a bit confused by the pin outs on the RGB Rotary Encoder, I think
I have ascertained that the 5 pins are

1 LED
2 LED
3 SWITCH
4 LED
5 +

and the 3 pins are named in order as
A - Rotary
C - Ground
B - Rotary

But Im not sure, the datasheet is a bit confusing. Is this correct ?

Are you talking about the Sparkfun RGB rotary encoder?

For the first set of pins “+” needs to be connected to 3.3v. SWITCH is low but goes high when the encoder’s stem is pressed. The LED pins light the corresponding colour of LED when that pin is grounded (I don’t think there’s an in-built resistor, so don’t forget that). If you look at the separate breakout board the pins are in the order Red, Green, SWITCH, Blue, Positive.

For the other three pins, C is Common and A and B are the directional pins. When you turn the stem in one direction A will connect to Common first and then B will. If you turn the stem in the other direction B connects to Common first, and then A will. If I remember right the example Arduino code which Sparkfun has sets the I/O pins connected to A and B as inputs held-high by pullup resistors, and Common to ground. That means A and B alternately go low depending on which direction you turn the stem in.

Which encoder is this? Could you link to the product page. Might help future tinkerers if we spent a couple of minutes whipping up a little pinout diagram for it.

This is the product.

It would be really helpful if you did the pinout diagram, I did work it out it seems but the spec sheet was a challenge to a basic learner.

The product tutorial and arduino project link are also broken on the product page.

I did try using it with an Arduino yesterday but wasnt succesful unlike the other parts I’ve ordered from you.

Would it be possible to make a schematic for an arduino or a Raspberry Pi for complete newbs like myself ?

Many thanks

Holy moly that datasheet is abysmal! My eyes actually hurt from looking at it.

For reference, the dimensional drawing has a much clearer description of the pin layout, although it’s still laid out like a visual puzzle:

Viewed from the top down (which is what I hope “mounting side” means) the row of 5 pins are, left to right, 1, 2, 3, 4, 5, and the 3 bottom pins are A C B (… yeah)

It looks like the LEDs accept a common power supply on pin 5, and pins 4, 2, 1 when pulled to ground will light the Blue, Green and Red LEDs respectively.

Pin 3 is a normally-open switch (for the push-button action of the encoder) which closes and connects pin 3 to pin 5. So you’d need a weak pull-down resistor between pin 3 and ground to set a consistent input value that’s then overridden when it’s connected to pin 5. So the switch will be LOW normally, and HIGH when pushed.

And as @shoe points out, C is the common connection for the rotary encoder itself, and A and B are connected to the wipers which alternate HIGH/LOW in a waveform pattern corresponding to the speed/direction of the encoder.

rotary-encoder-waveform

When turned Clockwise terminal A will go HIGH (or whatever your common signal is) first, and terminal B will follow after (depending on turn speed) and when turned Counter-Clockwise terminal B will go HIGH first, and terminal A will follow.

If you’re using a Raspberry Pi it can be a little tricky to keep up with the encoder at high speed. On an Arduino you should probably use an interrupt on pin A or B and then monitor the state of the other pin.

I should probably point out that when I tried this encoder I found it was very “bouncy” and difficult to get a script to register turns properly. I didn’t have much better luck with software debouncing, and ended up getting the DFRobot encoder which has hardware debouncing. I’m sure you could hook up hardware debouncing for the Sparkfun encoder too but I didn’t try that.

Yeah, they’re bouncy as all heck, a couple of capacitors and inline resistors help a lot.

I have a rotary encoder circuit in a drawer somewhere that works fairly well, I can’t recall what values I used!

so what values would i plug into this for pullup/activelow for the switch on a pi…
I have

dtoverlay=gpio-key,gpio=6,keycode=38,gpio_pull=down,active_low=0,label="rotary-switch"

but i get nothing from evtest when i press the button, tho it does show up in the list as

/dev/input/event0: button@6

and the encoder line

dtoverlay=rotary-encoder,pin_a=5,pin_b=13,relative_axis=1,linux_axis=6

makes the encoder part work in evtest