This is very helpful for adjusting a parameter that has huge values. That’s because the “Acceleration” mode is enabled, which increases the value quicker when you turn the encoder quickly. When you turn the encoder, the values don’t always increase linearly. This is what you get in the serial monitor when you turn the encoder: #include "AiEsp32RotaryEncoder.h" #include "Arduino.h" #define ROTARY_ENCODER_A_PIN 23 #define ROTARY_ENCODER_B_PIN 22 #define ROTARY_ENCODER_BUTTON_PIN 21 #define ROTARY_ENCODER_VCC_PIN -1 #define ROTARY_ENCODER_STEPS 4 //instead of changing here, rather change numbers above AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder ( ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS ) void rotary_onButtonClick () The current increment can be read easily at any time with the simple function provided by the library. It is recommended to use this library when measuring encoder values from a motor, where there will be hundreds of increments per second. However, its functionality is limited compared to other libraries there are no interrupts for each increment and no push button functionality. The advantage of this approach is that it doesn’t require any CPU processing, making it very performant. The ESP32Encoder library uses the PCNT peripheral on the ESP32 to perform counting operations. It utilizes hardware interrupts for incrementing calculations and is specifically adapted for rotary encoders with integrated push buttons, such as the KY-040 encoder. The AiEsp32RotaryEncoder library is an excellent choice for creating user interfaces, like menus, or for adjusting parameters. Two libraries that are well-suited for ESP32 are: It’s often better to use libraries rather than write your code. ![]() Some Arduino libraries compatible with the ESP32 The ESP32 can attach an interrupt to any output pins, which is impossible when using an Arduino, as only a few pins can have interrupts. At the same time, the accuracy of a potentiometer is determined by the resolution of the ADC that is used to measure its position. The precision of the encoder is based on the number of steps per rotation. You can physically feel the difference between the two a potentiometer rotates smoothly, while a rotary encoder turns jerkily.Ī rotary encoder is a device that can be easily used with a microcontroller, as it sends digital signals. A potentiometer changes the value of a resistor, but its range is limited.Ī rotary encoder can detect a specific number of “steps” for each revolution and sends a signal at each step. However, a potentiometer is an analog sensor while the rotary encoder is digital. Difference between rotary encoder and potentiometerĪt first, the rotary encoder KY-040 may look like a potentiometer. We can use this module to create a user interface for our program for example, to select options from a menu or change the value of a variable. This tutorial will explore utilizing a KY-040 rotary encoder module, a common component in DIY kits. The control button on 3D printers is usually a rotary encoder Getting started with a rotary encoder: the KY-040 ![]() Furthermore, many encoders used in DIY kits have a push button built-in. They’re mostly used in motors for PID control and user interfaces as an alternative to potentiometers. Rotary encoders are position sensors that measure an axis’s angular position (or rotation). Using a rotary encoder with Arduino Code with an ESP32
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |