Hola buen dia, soy nuevo en el mundo arduino y empece un proyecto para crear una especie de "odometro" con un encoder y una placa arduino mega. Utilice un codigo de libreria lo que me permitio contar los pulsos y mostrarlos, pero ahora necesito convertir esos pulsos a mm para proyectarlos en un display y no logro entender como hacerlo. Dejo la descripcion de los componentes y codigo:
Arduino mega 2560
Encoder Bourns ECW1J-B24-ACOO24L
La conexion es Pin C a tierra, pin A a entrada 2 y pin B a entrada 3 de arduino.
El codigo que use es el siguiente:
#include <Encoder.h>
// Change these pin 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 knobLeft(4, 5);
Encoder knobRight(2, 3);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft || newRight != positionRight) {
Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.print(newRight);
Serial.println();
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}
El encoder es de 24 pasos y cuenta 4 pulsos por cada paso, el diametro del eje es de 5mm entonces en una vuelta completa que son 96 pulsos deberia tener una medicion de 15.7mm.
Espero puedan ayudarme. Saludos!