Might be a speed problem - The Teensy is sooooo much quicker than this old slow Arduino Mega. But if you don't respect the forum rules, sharing code to reproduce the problem and details about wiring (i.e. schematics), pictures of you probing the A and B phase signals with an oscilloscope, etc., it's not easy to help you.
#include <Encoder.h>
#define motorHizA 5 // enable1
#define motorA2 7 // motor1ileri //Sag
#define motorA1 6 // motor1geri
#define motorB2 9 // motor2iler //sol
#define motorB1 8 // motor2geri
#define motorHizB 10 // enable2
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobLeft(28, 27);
Encoder knobRight(29, 30);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorHizA, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(motorHizB, OUTPUT);
}
long positionLeft = -999;
long positionRight = -999;
long newLeft, newRight;
void loop() {
newLeft = knobLeft.read();
newRight = knobRight.read();
analogWrite(motorHizA, 255);
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
analogWrite(motorHizB, 255);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.println(newRight);
if (newLeft != positionLeft || newRight != positionRight) {
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);
}
}wi
Code is Teensy sample code of teensy library Encoder .
https://www.pjrc.com/teensy/td_libs_Encoder.html .Sorry i do not have oscilloscope
.Wiring GND-GND , 5v to Encoder 5V and PİN27,28,29,30 connect to 5V with 10 K