Battery Management System
Battery Management System
Overview
Section titled “Overview”This section explains the battery management system (BMS) integrated into the ESP32-XIAO, focusing on the charging circuitry, power path management, and battery protection features. By the end of this section, you will be able to:
- Understand how the TP4054 charging IC works
- Describe the power path management between USB and battery
- Explain charging states and indicator behaviors
- Troubleshoot common battery charging issues
Prerequisites
Section titled “Prerequisites”Before starting this section, please ensure:
- Familiarity with LiPo battery characteristics (nominal voltage, charge voltage)
- Completed 04-01. ESP32-XIAO Hardware Overview
- Basic understanding of current and voltage measurements
Key Concepts
Section titled “Key Concepts”Battery Management System Overview
Section titled “Battery Management System Overview”The ESP32-XIAO integrates a complete battery management system on a single board, avoiding the need for external modules. The system consists of three functional blocks:
┌──────────────┐USB Power ──────────┤ │ │ TP4054 ├───── VCC (3.3V regulator) │ Charging IC │LiPo Battery ───────┤ │ └──────┬───────┘ │ ┌──────▼───────┐ │ Battery │ │ Voltage │──► ADC Pin (battery level monitoring) │ Divider │ └──────────────┘TP4054 Charging IC
Section titled “TP4054 Charging IC”The TP4054 is a standalone linear Li-ion battery charger designed for space-constrained applications.
Key Specifications:
| Parameter | Value |
|---|---|
| Charging method | Linear (constant current / constant voltage) |
| Charge current | Programmable up to 500 mA (typically 380 mA default on XIAO) |
| Charge voltage | 4.2V ± 1% (standard LiPo termination voltage) |
| Input voltage | 4.5V - 6.5V (USB 5V compatible) |
| Standby current | < 2 µA when charging complete |
| Protection features | Thermal regulation, reverse current blocking |
| Package | SOT-23-5 (ultra-small surface mount) |
Charging Profile:
The TP4054 follows the standard Li-ion CC/CV charging curve:
┌─────────────────────────────────┐ 4.2V │ ★ │ CV Phase (voltage constant, │ ★ │ current tapers down) │ ★ │ │ ★ │ Voltage│ ★ │ │ ★ │ │ ★ CC Phase │ │ ★ (current │ │ ★ constant) │ │ ★ │ │ ★ │ └─────────────────────────────────┘ Charge Current ────────────────► (Constant) (Tapering)Three Charging Phases:
- Trickle Charge: If battery voltage < 2.9V, charge at 10% of programmed current
- Constant Current (CC): Charge at full current (~380 mA) until 4.2V reached
- Constant Voltage (CV): Hold at 4.2V while current gradually drops to termination threshold (~10% of CC)
Power Path Management
Section titled “Power Path Management”The ESP32-XIAO implements a simple but effective power path scheme:
| Condition | Power Source | Battery State |
|---|---|---|
| USB connected, battery present | USB (5V) → 3.3V regulator | Battery charging |
| USB connected, no battery | USB (5V) → 3.3V regulator | N/A |
| USB disconnected, battery present | Battery → 3.3V regulator | Discharging |
| USB connected + battery full | USB (5V) → 3.3V regulator | Charging terminated |
Important behavior: When USB is connected, the board runs from USB power, and the battery charges independently. This means:
- The ESP32 sketch continues running normally while charging
- There is no reset or interruption when USB power is applied or removed
- The system seamlessly switches between power sources
Charging Indicators
Section titled “Charging Indicators”The XIAO provides a charging status LED (red):
| LED State | Meaning |
|---|---|
| Solid red | Battery is charging |
| Off | Battery fully charged, or no battery connected |
| Blinking | Fault condition (battery over-temperature, timeout) |
Battery Voltage Monitoring
Section titled “Battery Voltage Monitoring”The XIAO includes a resistor voltage divider connected to an ADC pin, allowing the ESP32 to read the current battery voltage:
Battery (+) ──┬── 100kΩ ──┬── ADC Pin (GPIO) │ │ │ 100kΩ │ │Battery (-) ──┴───────────┴── GNDThe voltage divider halves the battery voltage, bringing it within the ESP32’s 3.3V ADC range. The conversion formula in code:
float readBatteryVoltage() { int adcValue = analogRead(BATTERY_PIN); float voltage = (adcValue / 4095.0) * 3.3 * 2; // ×2 for divider return voltage;}Implementation Steps
Section titled “Implementation Steps”Step 1: Connect the Battery
Section titled “Step 1: Connect the Battery”The XIAO has a 2-pin JST connector on the backside:
Pin 1 (+): Battery positive (red wire)Pin 2 (-): Battery negative (black wire)Warning: Ensure correct polarity. Reversing the connection can damage the charging IC.
Step 2: Verify Charging
Section titled “Step 2: Verify Charging”void setup() { Serial.begin(115200); pinMode(BATTERY_PIN, INPUT);}
void loop() { float batteryVoltage = readBatteryVoltage(); Serial.print("Battery Voltage: "); Serial.print(batteryVoltage); Serial.println(" V");
if (batteryVoltage > 4.0) { Serial.println("Battery is fully charged"); } else if (batteryVoltage > 3.5) { Serial.println("Battery is charging or in normal range"); } else { Serial.println("Battery voltage low, consider charging"); }
delay(5000);}Step 3: Check Charging Current
Section titled “Step 3: Check Charging Current”To verify the charging current, measure the voltage across a known resistor in the charging path, or use a USB power meter. A properly charging XIAO should draw approximately 380-500 mA from USB.
Verification
Section titled “Verification”- Battery charges when USB is connected (red LED on)
- LED turns off when charge is complete
- ESP32 continues running when USB is connected/disconnected
- Battery voltage reading is within expected range (3.7V-4.2V)
- System switches to battery power when USB is disconnected
Troubleshooting
Section titled “Troubleshooting”Issue 1: Battery Not Charging
Section titled “Issue 1: Battery Not Charging”Symptom: Red LED stays off when USB is connected with battery present
Possible Causes:
- Battery already fully charged (check voltage with multimeter)
- Battery connected with wrong polarity
- Battery protection circuit triggered (some batteries have built-in protection)
Solution:
- Measure battery voltage with multimeter
- If voltage > 4.1V, battery is full — normal behavior
- If voltage is 0V, check polarity and connections
- Some protected batteries need a brief “kick” — connect to USB briefly with battery disconnected, then reconnect battery
Issue 2: Battery Voltage Reading Shows 0V
Section titled “Issue 2: Battery Voltage Reading Shows 0V”Symptom: ADC always reads 0
Possible Causes:
- ADC pin not configured correctly
- Battery not connected or connection is loose
- Voltage divider resistor damaged
Solution:
- Verify the ADC pin number matches your board variant
- Check JST connector is fully seated
- Measure voltage directly at the battery connector pads
Best Practices
Section titled “Best Practices”- ✅ Use protected LiPo batteries with built-in over-discharge protection
- ✅ Monitor battery voltage in firmware to prevent deep discharge (< 3.0V)
- ✅ Include a low battery warning in MQTT messages
- ✅ Charge at room temperature (0°C to 45°C recommended)
- ❌ Do not exceed the maximum input voltage (6.5V)
- ❌ Do not charge damaged or swollen batteries
- ❌ Do not leave batteries connected to a dead/disconnected XIAO for extended periods — the battery may discharge through the protection circuit
Summary
Section titled “Summary”- XIAO uses TP4054 — a compact, reliable Li-ion charger with CC/CV profile
- Built-in power path management allows simultaneous charging and operation
- Charging current is ~380 mA default, sufficient for most LiPo batteries
- ADC voltage divider enables battery level monitoring in firmware
- No external components needed — the XIAO is a complete BMS solution
References
Section titled “References”Target Audience: Alibaba.com IoT Pre-sales Engineers
Status: ✅ Completed