Encoder problem DIY steering wheel

I am despared i have been searching for any fix to my encoder not working then i saw this post Racing Wheel Rotary Encoder whont work. Because the thread had closed i cant reply any more. So the encoder i am using is the same as his that is: Photoelectric Incremental Rotary Encoder.pdf - Google Drive

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.

And also the code i used:

#define encoderPinA 0
#define encoderPinB 1

byte readingA = 0;
byte readingB = 0;
byte last_readingA = 0;
byte last_readingB = 0;

void setup() {
  Serial.begin (115200);

  pinMode(encoderPinA, INPUT);
  pinMode(encoderPinB, INPUT);
  // pinMode(encoderPinA, INPUT_PULLUP);
  // pinMode(encoderPinB, INPUT_PULLUP);
}

void loop() {
  last_readingA = readingA;
  last_readingB = readingB;
  readingA = digitalRead(encoderPinA);
  readingB = digitalRead(encoderPinB);
  if ((readingA != last_readingA) or (readingB != last_readingB)) // a or b has changed
  {
    Serial.print(readingA);
    Serial.print('\t');
    Serial.println(readingB);
  }
}

A schematic of your wiring would be less ambiguous than the written descriprion.

Please use schematics, not words. Pen and paper works well most times.

Thanks, that's the issue.

For some controllers this is bad. They use those pins for serial monitor as well as downloading code.
Which controller are You using?

Leonardo R3

Not the best but i thing better than words: Imgur: The magic of the Internet

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.

Yes i have, it is in first post. That is manufacture pdf with all the info i have on this encoder

I checked and on my board i can use pins 0 and 1. But i can change them if it will have a better chance to work.

Kindly share circuit diagram

Sorry, I missed the Leonardo part. According to the attachInterrupt reference, pins 1 and 2 are external interrupts on the Leo.

Here you go

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.

This is unclear. What do you mean by "touch the wire"?

When you use the test program of post #2 do you see the correct output sequence of A and B with the wiring you posted?

If that's true, the please try the Encoder library suggested in Post #6.

Yes

I just touch with my bare finger where ends of 2 resistor and 5v wire connect

I'm trying it right now and i get just 0 on serial monitor.

Yes

If this is the case, then you are wired correctly.

Please post the code you are using with the library.

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.

So now i dont get anything from program. Nothing at serial monitor

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.

// Arduino Leonardo (untested)
#elif defined(__AVR_ATmega32U4__) && !defined(CORE_TEENSY)
  #define CORE_NUM_INTERRUPT	5
  #define CORE_INT0_PIN		3
  #define CORE_INT1_PIN		2
  #define CORE_INT2_PIN		0
  #define CORE_INT3_PIN		1
  #define CORE_INT4_PIN		7

Stil i don't get anything even when i try to change pins. Last time i buy encoder from amazon without seeing issues on forums.

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?