How can I use Esp32encoder.h to read the value of my encoder motor?
I don’t have phase A and B togueter. My notor has just one phase.
It is a code that i’m try use.
#include <ESP32Encoder.h>
ESP32Encoder encM1;
ESP32Encoder encM2;hw_timer_t * timer = NULL;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;volatile int rpmL1 = 0;
volatile int rpmR1 = 0;
volatile int distanceR1 = 0;
volatile int distanceL1 = 0;void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&mux);rpmR1 = (encM1.getCount() * 60) / 893;
rpmL1 = (encM2.getCount() * 60) / 893;
distanceR1 += encM1.getCount();
distanceL1 += encM2.getCount();
encM1.clearCount();
encM2.clearCount();portEXIT_CRITICAL_ISR(&mux);
}void setup() {
Serial.begin(115200);// put your setup code here, to run once:
ESP32Encoder::useInternalWeakPullResistors = UP;
encM1.attachPin(12);
encM2.attachPin(14);
encM1.clearCount();
encM2.clearCount();timer = timerBegin(0, 80, true); // Inicializa timer com clock = 80 MHz
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 500, true);
timerAlarmEnable(timer);
}void loop() {
// put your main code here, to run repeatedly:
Serial.print(rpmR1);
Serial.print(” “);
Serial.print(rpmL1);
Serial.print(” “);
Serial.print(distanceR1);
Serial.print(” “);
Serial.println(distanceL1);
}
Hi Alexandre.
I’m not familiar with that library.
Can you share a link to the library that you’re using so that I can take a look?
Regards,
Sara
https://www.arduino.cc/reference/en/libraries/esp32encoder/
Hi Sara. This is a link that I’m using. Thank you.
I will try re install the arduino, I believe the issues could be by softaware. I will leave you know “Sara” about that.
Hi again.
Did you experiment their example: https://github.com/madhephaestus/ESP32Encoder/blob/master/examples/Encoder/Encoder.ino?
Regards,
Sara