Rotary Encoder Calibration Issues

I am using a Due with a rotary encoder with 1000 pulses. As I am using a Due I am using a level converter to reduce voltage to 3v from the encoder. The library in this example is EncoderStepCounter from GitHub - M-Reimer/EncoderStepCounter: Quadrature Encoder library for half-step and full-step encoders

The encoder is a 1000 pulse I have tried all sorts of code and other arduino boards but it will not align correctly. This set up is the most accurate so far but still not correct.

This pic is aligned at 0 (no revolutions

This pic is aligned 100 (one revolution clockwise)

This pic is aligned 600 (six revolutions clockwise)

This pic is aligned 1300 (thirteen revolutions clockwise)

Due Setup

Sketch I am currently using

#include “EncoderStepCounter.h”
#include <Wire.h>
#include <LiquidCrystal.h>

#define ENCODER_PIN1 49
#define ENCODER_INT1 digitalPinToInterrupt(ENCODER_PIN1)
#define ENCODER_PIN2 51
#define ENCODER_INT2 digitalPinToInterrupt(ENCODER_PIN2)
// Create instance for one full step encoder
EncoderStepCounter encoder(ENCODER_PIN1, ENCODER_PIN2);
// Use the following for half step encoders
//EncoderStepCounter encoder(ENCODER_PIN1, ENCODER_PIN2, HALF_STEP);

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

void setup() {
// Initialize encoder
// Initialize interrupts
attachInterrupt(ENCODER_INT1, interrupt, CHANGE);
attachInterrupt(ENCODER_INT2, interrupt, CHANGE);

// Call tick on every change interrupt
void interrupt() {

// This is an example on how to change a “long” variable
// with the library. With every loop the value is added
// and then cleared in the encoder library
double position = 0;
void loop() {
signed char pos = encoder.getPosition();
if (pos != 0) {
position += pos;

lcd.setCursor(0, 0);


Hi, @gatorsoft
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.

Then look down to “code problems” about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a link to data/spec of your encoder?
Can you post a circuit diagram please?

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Encoder specs I have… circuit diagram to follow.

I bought it off ebay a few years back and only have the advert specs as I couldn’t find a spec sheet.

1000 p/r (Single-phase 1000 pulses /R, Two phase 4 frequency doubling to 4000 pulses)

Power source: 5-24 VDC

Output: AB 2 phase output rectangular orthogonal pulse circuit, the output for the NPN open collector output type. Maximum mechanical speed: 5000 R / min response frequency: 0-l00Hz output:

NPN type open collector output (if the collector is not connected to Pull-up resistors, no voltage output)

Notice: AB 2phase output must not be directly connected with VCC, otherwise, will bum the output triode. Motor speed should be under 1000 RPM without Pull-up resistors

Connection: Green= A phase, white= B phase, red = power+, black= power -

Circuit diagram, sorry its a bit agricultural.

Thanks for the info, how are you powering the encoder.
A simple hand drawn circuit would be better with all components.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Sorry, powering the encoder from the Due 5V

As this is from China, and data is sketchy, you may have the 100 not 1000 ppt model.
A scope to look at the waveform would confirm this.

Have you tried two potential dividers for the drop to 3v3?

Have you a UNO or Nano to try the encoder on with 5V logic?

Tom… :grinning: :+1: :coffee: :australia:

Thanks for your assistance Tom.

LOL looks like I cooked my encoder.

Accidently plugged A into power now it wont work on any of my boards. Looks like I will need to order another and revisit this when it arrives.

Any recommendations on another one with at least 1000 pulses?

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