ESP32 battery voltage reading issue

I tested the Battery_power.ino example code on the WiFi LoRa32 V2 board. It worked perfectly. However, when I copied most of the code to the target application to read CO2 sensor via IIC code, the battery voltage always show full scale (4095 reading from analogRead(37) instruction). Here are the questions regarding the example code:

  1. In setup(),

    adcAttachPin(13);

  2. In loop(),

    uint16_t c = analogRead(37)XSMUL;

Is adcAttachPin(13) and analogRead(37) correct?

Any suggestion to resolve the battery voltage reading problem?

Peter

Try another set of I2C pins.

From the schematic diagram, we can see that when using pin 37 to read ADC, pin 21 needs to be pulled down, and pin 21 is the SDA pin. There are some conflicts. You can define other idle GPIOs as SDA pins.

Thank you for the detailed schematics. Pin 21 & pin 37 on the schematic is shown in the LiPo section:
image .

On the MCU section, there are two sets of number, which is pin #37? image|210x500 .
One #37 is VDD3P3_CPU.
One #37 & #6 is SENSOR_CAPP(GPI37). This is the correct one? What does #6 mean?

On the other side of MCU section, which is pin #21? image
One #21 is #21 & #15(SCL) (GPIO15…) which is connected to OLED D0
One #42 & #21 is (GPIO21). This is the correct one, right? What does the #42 mean?

Based on this analysis, I think I should be able to set GPIO#21 low to measure the Vbat, right?

Hi Shaffer:

I solve the battery reading problem by set GPIO#21 low during the setup() and measure the Vbat once. (I only check battery voltage at the power on). Then I initialize the IIC bus for the external sensor. This allows me to run the program without modify the board and change physical connection to the GPIO#21.

Thank you for your excellent support!!

Peter