Hi,
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() {
Serial.begin(250000);
lcd.begin(16,2);
lcd.clear();
// Initialize encoder
encoder.begin();
// Initialize interrupts
attachInterrupt(ENCODER_INT1, interrupt, CHANGE);
attachInterrupt(ENCODER_INT2, interrupt, CHANGE);
}
// Call tick on every change interrupt
void interrupt() {
encoder.tick();
}
// 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;
encoder.reset();
Serial.println(position/10);
lcd.setCursor(0, 0);
lcd.print(position/10);
}
}







