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! ![]()
}
//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;
}