Hi all.
Follow up for anyone in the same position.
I couldn't get the diode to show up with diode test function, my camera or in my test sketch with suspected pinouts
I have quite a few of these I'd like to use so I really wanted to figure this out.
In a last ditch effort I checked it in pitch black and caught a red glow.
I tested the pins of one that was turned on and found the polarity and voltages.
The pin outs are the same as most other 6 pin optical interrupters except its 1.5V at the IR diode:
After checking a few datasheets I've put an 100ohm @ 1.5V for the diode and everything is working now!
Sketch I've been using to test the encoder below
Encoder test
#define encoderDT 2
#define encoderCLK 3 // Interrupt
#define encoderSW 4
int previousDT;
int previousCLK;
int previousSW;
void setup()
{
Serial.begin(9600);
pinMode(encoderDT, INPUT_PULLUP);
pinMode(encoderCLK, INPUT_PULLUP);
pinMode(encoderSW, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(encoderCLK), doEncoder, CHANGE);
previousDT = digitalRead(encoderDT);
previousCLK = digitalRead(encoderCLK);
previousSW = digitalRead(encoderSW);
}
int encoderPos = 0;
int previousEncoderPos = 0;
void loop()
{
int actualSW = digitalRead(encoderSW); // Without debouncing
if (actualSW != previousSW)
{
Serial.print("SW= ");
Serial.println(actualSW);
previousSW = actualSW;
}
if(encoderPos > previousEncoderPos)
{
Serial.print(actualSW);
Serial.print(" ");
Serial.print(encoderPos);
Serial.println(" CW");
}
if(encoderPos < previousEncoderPos)
{
Serial.print(actualSW);
Serial.print(" ");
Serial.print(encoderPos);
Serial.println(" CCW");
}
previousEncoderPos = encoderPos;
// delay(1000);
delay(40);
}
void doEncoder()
{
int actualCLK = digitalRead(encoderCLK);
int actualEncoderDT = digitalRead(encoderDT);
if ((actualCLK == 1) and (previousCLK == 0))
{
if (actualEncoderDT == 1)
encoderPos--;
else
encoderPos++;
}
if ((actualCLK == 0) and (previousCLK == 1))
{
if (actualEncoderDT == 1)
encoderPos++;
else
encoderPos--;
}
previousCLK = actualCLK;
}
