Encoder basics - not consistent reads/click

Newb here, with a basic encoder that is not being read consistently. Sometimes it takes 1 click and sometimes up to 4 clicks to get encoder.h to print to serial monitor. NO extra caps or resistors on encoder.
encoder.h library, Straight connection to Teensey 4.0 pins 7, 8
Note I don't see in the docs how to pull the Teensey pins high w/encoder.
Basic stock test s/w is:

#include <Encoder.h>

Encoder myEnc(7, 8);
// 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);
}
}

Please post a wiring diagram (hand drawn is preferred). "Serial connection to Teensey 4.0 pins 7, 8" does not make sense.

Most likely, lack of pullup resistors is the problem.

1 Like

Hi JR.
"Serial" was a typo - should have been "straight".
Here is the schematic:

Pullup resistors to Vcc are required to give a HIGH level.

If you use the PJRC encoder library, the on-chip pullups should automatically be turned on.

SOLVED: replace encoder, now it works (no extra pullups added, am using PJRC Encoder lib).
Sorry to bother everyone.
----FYI there is conflict w/the declaring the encoder direction and joystick.button. Don't declare enc direction and all works fine).

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