main
ESP32 ESP-IDF component for inclinometer (via optical rotary encoder)
Features
- Quadrature encoder support with configurable GPIO pins.
- Configurable pull-up resistor enablement for encoder channels.
- Support for both clockwise and counter-clockwise rotation directions.
- Configurable pulses per revolution for accurate angle calculation.
- Position tracking with get and reset operations.
- PCNT glitch filter for noise rejection (1000ns).
- Multiple inclinometer instances support.
Attention
- The maximum value of encoder_pulses is 8191, limited by the PCNT counter range of +/-32767.
Using
In an existing project, run the following command to install the component:
cd ../your_project/components
git clone https://github.com/aZholtikov/zh_inclinometer
In the application, add the component:
#include "zh_inclinometer.h"
Examples
Basic Example
#include "zh_inclinometer.h"
zh_inclinometer_handle_t *inclinometer_handle = NULL;
void app_main(void)
{
esp_log_level_set("zh_inclinometer", ESP_LOG_ERROR);
zh_inclinometer_init_config_t config = ZH_INCLINOMETER_INIT_CONFIG_DEFAULT();
config.a_gpio_number = GPIO_NUM_26;
config.b_gpio_number = GPIO_NUM_27;
config.encoder_pulses = 3600;
esp_err_t ret = zh_inclinometer_init(&config, &inclinometer_handle);
if (ret != ESP_OK)
{
printf("Inclinometer initialization error: %s\n", esp_err_to_name(ret));
return;
}
ret = zh_inclinometer_reset(&inclinometer_handle);
if (ret == ESP_OK)
{
printf("Inclinometer position reset to zero.\n");
}
for (;;)
{
float angle = 0;
ret = zh_inclinometer_get(&inclinometer_handle, &angle);
if (ret == ESP_OK)
{
printf("Inclinometer position is %0.2f degrees.\n", angle);
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
zh_inclinometer_deinit(&inclinometer_handle);
}
Description
ESP32 ESP-IDF component for inclinometer (via optical rotary encoder).
92 KiB
0 Stars
1 Watchers
0 Forks
Languages
C
98.9%
CMake
1.1%