ESP32-C3 ADC odd behaviour

scuba-hacker
Posts: 3
Joined: Sun Dec 17, 2023 11:06 pm

ESP32-C3 ADC odd behaviour

Postby scuba-hacker » 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.
  1. const uint8_t BATTERY_ADC_PIN = GPIO_NUM_2;
  2.  
  3. pinMode(GPIO_NUM_2, INPUT);                        // disable pullup/down resistors
  4.  
  5. analogReadResolution(12);                               // 12 bit sample width (default)
  6. analogSetPinAttenuation(BATTERY_ADC_PIN, ADC_11db);      // 0-2.45V range for ESP32-C3 (default)
  7.  
  8. uint16_t adcVal = analogRead(BATTERY_ADC_PIN);
ADC-Voltage-Divider.png
ADC-Voltage-Divider.png (36.59 KiB) Viewed 13522 times

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32-C3 ADC odd behaviour

Postby boarchuz » Mon Dec 18, 2023 4:14 am

Schematic for your board reveals a 10k pullup on GPIO2:

https://dfimg.dfrobot.com/nobody/wiki/3 ... 106295.pdf

scuba-hacker
Posts: 3
Joined: Sun Dec 17, 2023 11:06 pm

Re: ESP32-C3 ADC odd behaviour

Postby scuba-hacker » Mon Dec 18, 2023 10:05 am

Awesome! Thank you so much @boarduz for pointing this out, I was pulling my hair out last night. Lesson for me is to exercise more caution over using the strapping pins (2,8,9) and to go back to the schematic. This is only the second board I've used so lots to learn.

scuba-hacker
Posts: 3
Joined: Sun Dec 17, 2023 11:06 pm

Re: ESP32-C3 ADC odd behaviour

Postby scuba-hacker » Mon Dec 18, 2023 10:41 am

I've switched to using GPIO3 and confirm all working! Thanks again.

Who is online

Users browsing this forum: No registered users and 54 guests