Optical Encoder from HP Printer

Simple project but very newbie to electronics. Trying to use an optical encoder and its mating 200 LPI, 1800 ct / rev wheel. Its a 4 wire guy with a 10,000 pF cap between power and ground.

Its most likely an Agilent 09863-58 but can't find exact specs on it, seems most follow wiring specs for HEDS-9711 (Google it I can't post links yet)

I'm putting ground wire to ground on arduino, Vcc to arduino 5V out, Channel A to Digital Pin 2, and Channel B to Digital Pin 3.

Is this all there is to wiring or am i missing part of the circuit? I see things about pull up resistors is that for mechanical detent encoders only?

With that said, will this code work (from bottom of Arduino Tutorials):

//PIN's definition

define encoder0PinA 2

define encoder0PinB 3

volatile int encoder0Pos = 0; volatile boolean PastA = 0; volatile boolean PastB = 0;

void setup() {

pinMode(encoder0PinA, INPUT); //turn on pullup resistor //digitalWrite(encoder0PinA, HIGH); //ONLY FOR SOME ENCODER(MAGNETIC)!!!! pinMode(encoder0PinB, INPUT); //turn on pullup resistor //digitalWrite(encoder0PinB, HIGH); //ONLY FOR SOME ENCODER(MAGNETIC)!!!! PastA = (boolean)digitalRead(encoder0PinA); //initial value of channel A; PastB = (boolean)digitalRead(encoder0PinB); //and channel B

//To speed up even more, you may define manually the ISRs // encoder A channel on interrupt 0 (arduino's pin 2) attachInterrupt(0, doEncoderA, RISING); // encoder B channel pin on interrupt 1 (arduino's pin 3) attachInterrupt(1, doEncoderB, CHANGE);

}

void loop() { //your staff....ENJOY! :D }

//you may easily modify the code get quadrature.. //..but be sure this whouldn't let Arduino back! void doEncoderA() { PastB ? encoder0Pos--: encoder0Pos++; }

void doEncoderB() { PastB = !PastB; }

Got the encoder working without any circuitry at all. I simply had to remove the pull up resistor code in the encoder examples page for "Tighten up ISRs" example.

The encoder datasheet i mentioned above is the wrong unit, its basically a HEDS-9700.

It provides a 0 Volt Low, 5 Volt High square wave ouptut, so simply putting channel A to Digital I/O 2 and B to 3 works awesome.

With this setup I am getting a resolution of 0.05°!!!!!

Code as follows:

enum PinAssignments { encoderPinA = 2, encoderPinB = 3, clearButton = 8 };

volatile unsigned int encoderPos = 0; unsigned int lastReportedPos = 1;

boolean A_set = false; boolean B_set = false;

void setup() {

pinMode(encoderPinA, INPUT); pinMode(encoderPinB, INPUT); pinMode(clearButton, INPUT); digitalWrite(clearButton, HIGH);

// encoder pin on interrupt 0 (pin 2) attachInterrupt(0, doEncoderA, CHANGE); // encoder pin on interrupt 1 (pin 3) attachInterrupt(1, doEncoderB, CHANGE);

Serial.begin(9600); }

void loop(){ if (lastReportedPos != encoderPos) { Serial.print("Index:"); Serial.print(encoderPos, DEC); Serial.println(); lastReportedPos = encoderPos; } if (digitalRead(clearButton) == LOW) { encoderPos = 0; } }

// Interrupt on A changing state void doEncoderA(){ // Test transition A_set = digitalRead(encoderPinA) == HIGH; // and adjust counter + if A leads B encoderPos += (A_set != B_set) ? +1 : -1; }

// Interrupt on B changing state void doEncoderB(){ // Test transition B_set = digitalRead(encoderPinB) == HIGH; // and adjust counter + if B follows A encoderPos += (A_set == B_set) ? +1 : -1; }

Thank you for the code!!!