Feather ESP32 V2 with no battery, has value on the battery pin?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
BoulderFish
 
Posts: 4
Joined: Fri Dec 13, 2024 10:04 am

Feather ESP32 V2 with no battery, has value on the battery pin?

Post by BoulderFish »

I have a Feather ESP32 V2 with the battery currently disconnected.

Any idea why the following code would print the following:
"rawADC value: 2074.00, Current battery voltage : 4.15"

I would/should expect the rawADC value to be approx 0 (if not actually 0) when no battery is connected, no?

Code: Select all

#define ADC_BATTERY A13

//=================================================
// getBatteryLevelAsPct()
// Gets the current battery charge level as a percentage.
//
uint8_t REBatteryHuzzahFeather::getBatteryLevelAsPct()
{
    uint8_t retVal = 0;

    float rawADC = analogReadMilliVolts(ADC_BATTERY);   //the value obtained directly at the battery pin (which half of a voltage divider circuit, and in mV)
    float currentVoltage = (rawADC * 2.0)/1000.0;     // Since our reading is half the voltage, and in mV, double the value and divide by 1000 to get voltage.

String batteryStatus = "rawADC value: " + String(rawADC) + ", Current battery voltage : " + String(currentVoltage);
Serial.println(batteryStatus);

    [code to calculate charge pct here] 
    
    return( retVal );
}
By the way, when I run this code on the previous gen Feather ESP32 (not V2), it appears to work as expected. It's like Adafruit changed the battery pin to something different than A13 for the ESP32 V2, but didn't update their documentation.

Thanks in advance for any thoughts on this.

User avatar
mikeysklar
 
Posts: 18608
Joined: Mon Aug 01, 2016 8:10 pm

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by mikeysklar »

Try the Feather V2 example code under Measuring Battery. It is using A13 still. Maybe the resistor divider circuit is different?

Code: Select all

// Arduino Example Code snippet

#define VBATPIN A13

float measuredvbat = analogReadMilliVolts(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat /= 1000; // convert to volts!
Serial.print("VBat: " ); Serial.println(measuredvbat);
The Voltage Monitor pin GPI35 is mapped to A13 in the pins_arduino.h file.

Code: Select all

sklarm@grazie adafruit_feather_esp32_v2 % pwd
/Users/sklarm/Library/Arduino15/packages/esp32/hardware/esp32/3.1.1/variants/adafruit_feather_esp32_v2
sklarm@grazie adafruit_feather_esp32_v2 % grep "A13\|35" pins_arduino.h
static const uint8_t A13 = 35;
#define BATT_MONITOR 35
Screenshot 2025-01-19 at 10.18.00 AM.png
Screenshot 2025-01-19 at 10.18.00 AM.png (269.42 KiB) Viewed 78 times

User avatar
BoulderFish
 
Posts: 4
Joined: Fri Dec 13, 2024 10:04 am

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by BoulderFish »

Thanks, Mike, but yeah, even when I change my ADC_BATTERY #define to 35, I get the same result. The below code prints:
rawADC value (from pin 35): 2427.00, Current battery voltage : 4.85

Code: Select all

#define ADC_BATTERY 35

//=================================================
// getBatteryLevelAsPct()
// Gets the current battery charge level as a percentage.
//
uint8_t REBatteryHuzzahFeather32V2::getBatteryLevelAsPct()
{
    uint8_t retVal = 0;

    float rawADC = analogReadMilliVolts(ADC_BATTERY);   //the value obtained directly at the battery pin (which half of a voltage divider circuit, and in mV)
    float currentVoltage = (rawADC * 2.0)/1000.0;     // Since our reading is half the voltage, and in mV, double the value and divide by 1000 to get voltage.
 
    String batteryStatus = "rawADC value (from pin " + String(ADC_BATTERY) + "): " + String(rawADC) + ", Current battery voltage : " + String(currentVoltage);
    Serial.println(batteryStatus);

    [code to determine battery charge as pct]

    return(retVal);
}
Correct me if I'm wrong (very possible), but even if the divider circuit is different, with no battery connected, I expect my rawADC value to be ~0. Or, is the 2427 (+/-) value I'm receiving from analogReadMilliVolts([battery pin]) supposed to translate to ~0 somehow?

Btw, the Feather V2 example code under Measuring Battery is what I saw prior to posting that made me wonder if the pin changed for Feather ESP32 V2 but Adafruit forgot to update in some places.

Thanks again Mike for your thoughts and time. I still must be either doing something wrong, or interpreting something incorrectly.

-BoulderFish

mikeysklar wrote: Sun Jan 19, 2025 2:19 pm Try the Feather V2 example code under Measuring Battery. It is using A13 still. Maybe the resistor divider circuit is different?

Code: Select all

// Arduino Example Code snippet

#define VBATPIN A13

float measuredvbat = analogReadMilliVolts(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat /= 1000; // convert to volts!
Serial.print("VBat: " ); Serial.println(measuredvbat);
The Voltage Monitor pin GPI35 is mapped to A13 in the pins_arduino.h file.

Code: Select all

sklarm@grazie adafruit_feather_esp32_v2 % pwd
/Users/sklarm/Library/Arduino15/packages/esp32/hardware/esp32/3.1.1/variants/adafruit_feather_esp32_v2
sklarm@grazie adafruit_feather_esp32_v2 % grep "A13\|35" pins_arduino.h
static const uint8_t A13 = 35;
#define BATT_MONITOR 35

Screenshot 2025-01-19 at 10.18.00 AM.png

User avatar
T_Mo
 
Posts: 1711
Joined: Thu Mar 15, 2018 7:10 pm

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by T_Mo »

(Community member)
If you don't have a battery connected, the voltage monitor circuit is still being driven by the LiPO battery charger circuitry.

It doesn't necessarily turn off to 0 volts when you don't connect a battery, since it has to keep testing the voltage and current there to detect when you do connect a battery.

User avatar
BoulderFish
 
Posts: 4
Joined: Fri Dec 13, 2024 10:04 am

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by BoulderFish »

T_Mo wrote: Sun Jan 19, 2025 4:18 pm (Community member)
If you don't have a battery connected, the voltage monitor circuit is still being driven by the LiPO battery charger circuitry.

It doesn't necessarily turn off to 0 volts when you don't connect a battery, since it has to keep testing the voltage and current there to detect when you do connect a battery.
Thanks, that makes sense. But that still leaves questions (at least for me anyway): So, what exactly is the value on that VBAT pin (pin 35) representing? Or, put another way, how is it expected to be interpreted, so that it's usable in some way?

What I think I know is that it's literally a direct connection to a point on the board between two resistors (equal value resistors I think I've read?) serving as a voltage divider downstream of the battery connection, and analogReadMilliVolts([VBAT PIN]) gets me the voltage reading (in mVs) from that point.

But how does the voltage monitor circuit affect that voltage? We would need to understand that in order to account for it, right?

Thanks again, T_Mo.

User avatar
T_Mo
 
Posts: 1711
Joined: Thu Mar 15, 2018 7:10 pm

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by T_Mo »

The voltage monitor connected to A13 (pin 35) is a resistor ladder made up of two 200K resistors.
So the voltage at A13 is 1/2 of the value at VBAT. There is a 1uF filter capacitor across the lower resistor, so that will smooth out the readings a little. It's RC time constant is around 0.1 seconds.

If you don't have a battery connected, the VBAT voltage has no useful meaning. It's an output from the battery charger chip that is designed to have a battery connected. Without a battery, it's useless, because the chip is going to keep intermittently testing you've just connected a battery. So it'll change the voltage, see if any current is flowing, measure the voltage, and do something else based on those current and voltage values.

To the external user, it looks like the battery charger is generating random noise. The 1 uF capacitor across the lower 200K resistor will smooth out the values a little.

If you want to use the A13 value to imply whether you have a battery connected, you'll have to do some experiments and see if works reasonably well.

When you have a LiPO battery connected, you'll get 1/2 of the battery voltage.
- When a battery is nearly empty and is starting to charge, the voltage will be somewhere below 3.5V, while the charger is trickling some charge into the battery to avoid giving it a current surge.

- Once the charger starts increasing the charge current, the battery voltage will quickly head toward 4.0 volts.

- As the battery gets full, the voltage will slowly climb toward 4.2 volts.

- Once the charger thinks the battery is full, it will shut off the charging current, and the VBAT voltage will instantly drop to around 4.1 volts.

- When the battery is discharging, the voltage will fall fairly linearly down to 3.5 volts, then it will start to plummet. The battery's internal protection circuit cuts off around 3.0 volts or so. But your processor will probably stop working before then, once the Feather's 3.3V regulator shuts down due to insufficient battery voltage.

User avatar
BoulderFish
 
Posts: 4
Joined: Fri Dec 13, 2024 10:04 am

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by BoulderFish »

Hey T_Mo, thanks a TON for this - Looks like it's going to be super helpful with getting things to work the way I would like.

Thanks again!

User avatar
T_Mo
 
Posts: 1711
Joined: Thu Mar 15, 2018 7:10 pm

Re: Feather ESP32 V2 with no battery, has value on the battery pin?

Post by T_Mo »

No problem. I've played around with a lot of battery experiments on Feather boards.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”