I'm in the same situation as autor. I uplouded code to arduino and wired like was said 5v from arduino to Vcc(to encoder) and to 2 resistors 10k and other end of each resistors to data cable A and B from encoder, ground to ground. On arduino i'm getting 0 0 output in serial monitor when not doing anything or turning encoder. Also when i touch the wire from 5v past resistors that are connected to A and B from encoder the serial port shows 00|01|11|10|00 so i guess that good. But the problem is the turning of encoder does not change value on serial monitor.
Wiring looks OK for an encoder with open collector outputs. Are you sure of the output type? Do you have a data sheet for the encoder?
You are using the serial port. As @Railroader pointed out, pins 0 and 1 are the hardware serial pins. Use different pins for your encoder.
I would use the Encoder library with that encoder. The Encoder library uses 1 or 2 external interrupt pins (pins 2 and 3 on an Uno) to read the encoder. That is more accurate at higher speeds. Encoder library documentation.
That picture shows the interesting things. Why Imgur thinks it's important to show all the green/blue surface and the none female shape of the controller I don't understand. Never mind, the message is clear.
I used program for two knobs because in my IDE i cant just open from example code from Encoder library
#include <Encoder.h>
Encoder knobLeft(0, 1);
Encoder knobRight(2, 3);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft || newRight != positionRight) {
Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.print(newRight);
Serial.println();
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}
That's because the example files are .pde and not .ino in the version you are using.
The library manager does not update to the latest version. Download the version 1.4.3 .zip file from GitHub and install it. The examples are .ino and will open from the ide.
That said, I don't understand why you get simple test output but not output with more complete code.
I see this in the interrupt_pins.h file of the Encoder.h library. which says the Leonardo with interrupts is "untested". Try using the NoInterrupts.ino file of the library.
As I said before, I don't understand why the simple A/B test output program works correctly, and code to read the quadrature pattern from those same A/B outputs does not increment or decrement as expected.
I can set up a Leonardo to test with an encoder I have, but it's not clear that will provide any additional information for your specific encoder.
Do you have a Uno or another Arduino to test with?