Reading 3.3 in the ADC of the ESP32-S2

frotaitalos
Posts: 13
Joined: Tue Nov 01, 2022 8:32 pm

Reading 3.3 in the ADC of the ESP32-S2

Postby frotaitalos » Thu Feb 02, 2023 3:00 pm

Hi Guys, I'm trying to read the variation of a potentiometer with my esp32-s2 from 0-3.3V. I've done some research here on the forum and I saw that for that I should activate the 13bit reading and the 11db attenuation, as I saw in the following post

"https://esp32.com/viewtopic.php?t=21969"

But doing that, my esp32-s2 keeps reading only up to 2.5 volts, after that I have a ghost zone on the potentiometer axis. Is there anyone here who was successful in this implementation? I don't want to have to generate the necessary attenuation via hardware.

Code: Select all

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <soc/adc_channel.h>
#include <soc/rtc.h>
#include <driver/adc.h>
#include <esp_adc_cal.h>
#include <esp_log.h>

static const char* TAG = "test";

void app_main() {
    adc1_config_width(ADC_WIDTH_BIT_13);
    adc1_config_channel_atten(ADC1_GPIO1_CHANNEL, ADC_ATTEN_11db);

    for (;;) {
        int raw = adc1_get_raw(ADC1_GPIO1_CHANNEL);
        ESP_LOGI(TAG, "%d", raw);

        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

Who is online

Users browsing this forum: No registered users and 188 guests