Interfacing Encoder Switch with ESP 32
Posted: Sun Mar 29, 2020 8:59 am
Hi,
I am interfacing ESP32 with an encoder switch and not able to read it properly in both directions. If I limit it to one direction, it works almost fine.
Here is the configuration:
Interrupt Routine is line this:
Could you please suggestion what could be the issue?
I am interfacing ESP32 with an encoder switch and not able to read it properly in both directions. If I limit it to one direction, it works almost fine.
Here is the configuration:
Code: Select all
#define ENC_DATA 25
#define ENC_CLK 33
#define ENTER 26
inside main before while(1):
gpio_set_direction(ENTER, GPIO_MODE_INPUT);
gpio_pullup_en(ENTER);
gpio_set_direction(ENC_CLK, GPIO_MODE_INPUT);
gpio_set_intr_type(ENC_CLK, GPIO_PIN_INTR_NEGEDGE);
gpio_intr_enable(ENC_CLK); // Enable Interrupt
gpio_pullup_en(ENC_CLK);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//remove isr handler for gpio number.
gpio_isr_handler_remove(ENC_CLK);
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(ENC_CLK, gpio_isr_handler, (void*) ENC_CLK);
gpio_set_direction(ENC_DATA, GPIO_MODE_INPUT);
gpio_pullup_en(ENC_DATA);
Interrupt Routine is line this:
Code: Select all
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint8_t tmp = 0;
tmp = gpio_get_level(ENC_DATA);
if(tmp) // if pin is high
{
if(cct < 200) cct++;
else cct = 200;
}
else // If pin is low
{
if(cct > 0) cct--;
else cct = 0;
}
}
In the main loop I am displaying the cut variable on a display 4 digits to see whats going on.