ESP32 LiPo/Why a battery board/01. Unplug it and it keeps running
Why a battery board · 01 of 13

Unplug it and it keeps running

Plug a lithium cell into this ESP32 and the USB-C cable does two jobs: it runs the board and it charges the cell. Pull the cable out and the cell takes over before the 3.3 V rail can notice, so the sketch carries on running.

Two sources, one rail

The ESP32 runs on 3.3 V. On this board a regulator makes that 3.3 V from whichever source it is given: 5 V from USB-C, or a lithium cell somewhere between 3.0 V and 4.2 V. Between the two sources and the regulator is a power-path circuit that picks one of them.

While USB is plugged in, it picks USB. The board runs from the cable, and a charger on the same board fills the cell from the same cable at up to 500 mA. When the cable comes out, it picks the cell.

Pull the USB cable out, and nothing happens
on USB
Running from
USB
3.3 V rail
3.30 V
Resets
0
USB is in. The board runs from it, and the charger fills the cell at the same time. Press the button to pull the cable.

Why the sketch does not reset

The ESP32 resets when its supply falls to about 2.43 V. What the handover changes is the regulator's input — from 5 V to the cell's 3.7 V or so — and the regulator does not mind which it gets, as long as it stays a few tenths of a volt above the 3.3 V it is making. Both do. The output, which is all the ESP32 sees, stays where it was.

Plug the cable back in and the same thing happens the other way: USB takes the load and the charger starts again.

What it is for

  • A project that moves: a handheld, a robot, a sensor you carry from room to room.
  • A bench project that should survive the cable being knocked out.
  • A project on a USB charger that should ride through a power cut, for as long as the cell lasts.

What it does not do

It does not make the ESP32 frugal. With Wi-Fi on all the time the chip draws around 120 mA, and a 1000 mAh cell is gone in hours. Weeks on one cell means deep sleep, which is its own article.

It also only charges from USB-C. There is no battery pin and no 5 V pin on the header, so a cell charges through the socket and nowhere else.

When it does not work

It resets when I pull the USB cable out

There is no cell for it to switch to, or the cell is too low to hold the rail. On a shield, check the switch is at ON and the cable from TO ESP32 is in the board's socket. Then charge the cell for an hour with USB in and try again.

It runs on USB but not on the cell alone

The cell is flat, or its protection circuit has switched it off after running it flat. Leave USB plugged in with the cell connected: the charger wakes a cell like that, and after a few minutes the board should run without the cable.

Does it charge while my sketch is running?

Yes. The cable supplies the board and the charger at the same time, and the sketch cannot tell the difference. A board left plugged in runs its program and fills the cell.

Where this goes next

One lithium cell, with a protection circuit, big enough for a 500 mA charger.

The cell to buy

Edit this page — content/books/esplipo/unplug-and-keep-running.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

ESP32 LiPo Dev Kit: 3 Boards with LiPo Charger + 3 Shields

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum