Total newbie on Arduino here, and have a question about programming using encoders. I have an encoder (CTS 288T232R161A2) that I would like to send a keyboard press to my PC when rotating one way, and another keyboard press when rotating the other way. Example Rotate CW = A, rotate CCW = B.
I have searched the forums here, but can't find a solution for this encoder type. As far as I can see, the encoder sends 2-bit binary code, and that needs to be deciphered somehow to allow the Arduino Micro to know which way it is rotating. But I can't figure out how to make this work...
The encoder has three terminals (A, B and C ("Ground")). It also sends a 2-bit binary "code" when it's rotated:
I think it is relative easy to decode. On the rising edge of one of the outputs sample the other bit at that time should give you direction. High would be clockwise and low would be counterclockwise. If I am wrong switch the output pins. You do need a pull up resistor on each output and the common grounded. If you look around I believe most of the rotary encoder libraries and code will work.
Thanks, but there is something I obviously don’t understand.
So, if I sample pin A and listen for a rise, then read pin B to figure out the direction of turn, the logic would go something like this (right?):
In Position 1:
Pin A = LOW
Pin B = LOW
I turn to position 2:
Pin A = HIGH
Pin B = LOW
Hence, I can say that I’ve turned CW.
I continue to turn to position 3:
Pin A = HIGH
Pin B = HIGH
Now I have two problems. First, Pin A remains HIGH, so there is no RISE/CHANGE, right? Hence I cannot trigger of a RISE/CHANGE?
And Pin B now is HIGH, hence, opposite of when I turned from position 1 to 2. So if I say in my code that pin B = LOW is equal to CW turn, that would no longer be true for a switch from position 2 to 3, as pin B now reads HIGH for a CW turn.
I could maybe trigger of changes to both Pin A and B, and tell the code to look at the opposite pin to read it’s status, but I would still have the same same problem it looks like to me.
Or have I misunderstood something fundamental here?