Activity › Forums › Questions & Troubleshooting › Encoder on MINI › Reply To: Encoder on MINI
-
For those who may need this answered in the future.
After doing a bit of digging, I discovered this thread:
https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/issues/26
Which eventually led to this solution:
In short, I simply needed two “pull-up resistors.” To solve my problem and get the LPD3806 encoder working, I added a resistor (I used a 6.8kOhm) to both input pins (Input0 and Input1) in the same input screw terminals that the Encoder leads were attached. I connected the resistors to the 12v power supply.
In the Code, I changed pinMode(1, INPUT_PULLUP); and pinMode(2, INPUT_PULLUP); to pinMode(1, INPUT); and pinMode(2, INPUT);
WORKS GREAT! This is the code Used to read the encoder (I did not use the CONROLLINO.h library for this project):
//***************************BEGIN CODE******************************
unsigned long A = 3;
unsigned long B = 2;
unsigned long currentStateA;
unsigned long lastStateA;
unsigned long pulse;
unsigned long previousPulse;
void setup () {
pinMode(A,INPUT); // not INPUT_PULLUP since we are attaching external Pullup reistors
pinMode(B,INPUT); //not INPUT_PULLUP since we are attaching external Pullup reistors
lastStateA = digitalRead(A);
Serial.begin(9600);
}
void loop() {
currentStateA = digitalRead(A);
if (currentStateA != lastStateA && currentStateA == 1){
if (digitalRead(B) != currentStateA) {
pulse –;
}
else {
pulse ++;
}
}
lastStateA = currentStateA;
//delay(1) you may need to add a very short delay here to de-bounce signal depending on // your speed (RPM)
if (pulse != previousPulse) {
Serial.println(pulse);
}
previousPulse = pulse;
}
//*******************************END CODE*****************************
Controllino is a great product, I wish it had switches to disable the internal pull-down resistors to allow for “INPUT_PULLUP’ code to be used, but hopefully this answer helps someone in the future.
-
This reply was modified 3 years, 9 months ago by
Johnnycatt.
-
This reply was modified 3 years, 9 months ago by