Quadrature encoder output values continuously climbing (Teensy 4.0)

The encoder has A+ A- B+ B- VCC and GND pins. When I connect A+ and B+ to the teensy on various pins and run the following code my serial output is just a continuously, and rapidly, climbing set of numbers. Any tips?

#include <Arduino.h>


#include <Encoder.h>

// Change these two 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 myEnc(3, 4);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

I guess the A- and B- pins must be connected too. Post a link to the datasheet of the device!

The encoder needs to have Vcc and GND connected, as well.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.