Code: Select all
#define BATTERY_EN_NBR (GPIO_NUM_32)
int voltage;
...
ESP_ERROR_CHECK(gpio_set_level(BATTERY_EN_NBR, 1));
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_10));
ESP_ERROR_CHECK(adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_11));
voltage = adc1_get_raw(ADC1_CHANNEL_7);
ESP_LOGI(TAG, "battery voltage is %x.", voltage);
ESP_ERROR_CHECK(gpio_set_level(BATTERY_EN_NBR, 0));