Reading rotary encoder (getting random values)
Posted: Sat Apr 16, 2016 9:48 am
I'm trying to read rotary encoder with this simple code i found from Arduino forums:
Of course with similar xc code. But just getting random values when reading the pins. I also tried debouncing i'm using for buttons (just simple timer), but still cannot get steady reading. It is connected straight to 1-bit pins and middle pin to ground.
Encoder is Piher CI-11 (2 bit in quadrature code).
Does anyone have an example how to properly read the encoder or give any tips how to interface it properly to startKit and reading algorithm.
Code: Select all
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}
}
encoder0PinALast = n;
Encoder is Piher CI-11 (2 bit in quadrature code).
Does anyone have an example how to properly read the encoder or give any tips how to interface it properly to startKit and reading algorithm.