ESP32-C3 ADC odd behaviour
Posted: Sun Dec 17, 2023 11:57 pm
I'm using a DFRobot ESP32-C3 and want to monitor it's battery voltage using ADC1 GPIO 2. The circuit for connecting up GPIO2 is a voltage divider and a capacitor. I've verified the resistor values with a multimeter and tested for continuity.
The problem is that despite the supply into the top of the voltage divider being 3.7V, the multimeter shows 2.85V at GPIO 2. The code below returns a saturated value of 4095. I was expecting to see 1.85V at GPIO2 and an ADC reading of around 3000.
I'm using the latest platformio core for the build.
The problem is that despite the supply into the top of the voltage divider being 3.7V, the multimeter shows 2.85V at GPIO 2. The code below returns a saturated value of 4095. I was expecting to see 1.85V at GPIO2 and an ADC reading of around 3000.
I'm using the latest platformio core for the build.
- const uint8_t BATTERY_ADC_PIN = GPIO_NUM_2;
- pinMode(GPIO_NUM_2, INPUT); // disable pullup/down resistors
- analogReadResolution(12); // 12 bit sample width (default)
- analogSetPinAttenuation(BATTERY_ADC_PIN, ADC_11db); // 0-2.45V range for ESP32-C3 (default)
- uint16_t adcVal = analogRead(BATTERY_ADC_PIN);