Linear encoder from printer, can't get it to work - RESOLVED

EDIT : SOLUTION :slight_smile:

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 :slight_smile:

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:

And my code is the basic example from the library zip file:

/* Encoder Library - Basic Example
 * 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.println("Basic Encoder Test:");

long oldPosition  = -999;

void loop() {
  long newPosition =;
  if (newPosition != oldPosition) {
    oldPosition = newPosition;


I added


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,

1 Like

did you tried with a slotted wheel?

did you tried with a slotted wheel?

Yes I did, but didn't work with this encoder - got it to work though, see opening post with edit.