============================
EDIT : SOLUTION
Seems the encoders are picky on what strip is used !
When I hooked up the original pair from the printer with the connections and code below it works
Hi all,
I'm trying to use a q9846 or Q9864 to measure displacement.
Now I hooked it up to my arduino uno and also mega like this:
(pinout from datasheet)
I'm using this library:
https://www.pjrc.com/teensy/td_libs_Encoder.html
And my code is the basic example from the library zip file:
/* Encoder Library - Basic Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(2, 3);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
Serial.println(digitalRead(2));
Serial.println(digitalRead(3));
}
I added
Serial.println(digitalRead(2));
Serial.println(digitalRead(3));
To see the input on the pins. But they both stay at 1 constantly.
Also if I put a piece of paper into the encoder. Shouldn't they do to zero then ?
I tested with two different Q9846 encoders and oneQ9864.
What am I doing wrong here ?
Any hint would be welcome,
Thanks