• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Esp32encoder.h one pin.

Q&A Forum › Category: ESP32 › Esp32encoder.h one pin.
0 Vote Up Vote Down
ALEXANDRE RPEREIRA asked 4 years ago

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);
}

Question Tags: Esp32encoder.h
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
ALEXANDRE RPEREIRA answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi again.
Did you experiment their example: https://github.com/madhephaestus/ESP32Encoder/blob/master/examples/Encoder/Encoder.ino?
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.