Charger
Using TP4056 Charger with Raspberry Pi
What is the TP4056?
TP4056 practical reference
The standard single-cell lithium charging module, often bundled with over-charge/discharge protection circuitry on the same board. Built around the TP4056 linear charger IC (commonly paired with a DW01 protection chip and dual MOSFETs), it takes a 5V USB input and safely charges a single-cell Li-ion/LiPo battery with the correct constant-current/constant-voltage profile, while the protection circuitry cuts off the battery if it's charged too high, discharged too low, or short-circuited — making it the near-universal choice for any DIY project that charges its own lithium battery from USB.
Key specifications
- Chipset: TP4056 linear Li-ion/LiPo charger IC, commonly paired with a DW01A protection IC and dual MOSFETs on the same board
- Input voltage: 4.5V–5.5V DC, typically via Micro-USB or USB-C connector
- Charge voltage: 4.2V constant-voltage regulation for standard single-cell Li-ion/LiPo
- Charge current: Adjustable via an onboard resistor (commonly set to ~1A by default, some boards include a resistor pad to change it)
- Charge algorithm: Constant-current / constant-voltage (CC/CV) with automatic trickle charge for deeply discharged cells and charge termination near full
- Protection features (on modules with DW01): Over-charge protection, over-discharge protection, over-current/short-circuit protection
- Status indication: Onboard LEDs typically indicate charging (red) and fully charged (blue/green), color scheme varies by board
- Interface: Passive power circuit — USB in, battery and load out, no digital interface required
Pinout and connection notes
Always verify whether your specific TP4056 board includes the DW01 protection chip (look for two extra small MOSFETs and a small SOT23-6 IC near the battery terminals) — bare TP4056-only boards without protection should never be used to directly power a load while charging, since an over-discharged or over-charged unprotected cell is a real fire risk. Boards with protection expose separate B+/B- (battery) and OUT+/OUT- (load) pads so the load can draw power safely even during charging.
- IN+ (USB VBUS): 5V input from USB, via Micro-USB or USB-C connector
- IN- (GND): USB ground
- B+ (Battery+): Connect to the positive terminal of the single-cell Li-ion/LiPo battery
- B- (Battery-): Connect to the negative terminal of the battery
- OUT+: Positive output to the project load, present on boards with a protection circuit and separate load output
- OUT-: Negative output to the project load
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.
Setting Up TP4056 with Raspberry Pi
Library
Adafruit-MCP3008 by Adafruit
pip3 install adafruit-circuitpython-mcp3xxx
Wiring
| Component pin | Raspberry Pi pin | Note |
|---|---|---|
| IN+ / IN- | USB / power adapter | Charging input — not connected to the Pi |
| B+ / B- | — | To the single-cell Li-ion/LiPo battery |
| OUT+ | Through an MT3608 boost, into 5V pin or USB power | The Pi needs a genuinely stable 5V at real current — a boost converter rated for your model's peak draw is required, not optional |
| OUT- | GND |
Swipe sideways to see every column →
- The Pi's own supply comes from the boosted 5V rail (see the MT3608 page for that half of the setup) — you still need an external ADC like this MCP3008 to actually measure battery voltage, since the Pi has no analog input pins.
- A single 18650/LiPo cell through a typical boost converter is realistically enough current for a Pi Zero or Pico, but marginal-to-insufficient for a Pi 4/5 under real load — check your boost module's rated output current against your Pi model's peak draw.
- Same LED-vs-actual-charge caveat as the other boards.
Related Components
18650 Holder
Single-cell 18650 holder for portable project power.
AMS1117 33
Fixed 3.3V linear regulator for powering logic-level components.
LM2596
Adjustable buck converter for efficiently stepping down higher voltages to project logic levels.
MT3608
Adjustable step-up converter for boosting low battery voltages to component requirements.
Related Guides & Projects
Raspberry Pi Pico W and Pico 2 W: Install MicroPython with Thonny or UF2
Hold BOOTSEL, drag the correct UF2 file, open the REPL and blink the onboard LED. Includes the Pico vs Pico W vs Pico 2 W firmware differences and what to do when the drive does not appear.
Raspberry Pi Pico W Web Server in MicroPython: Control an LED and Read a Sensor
Connect the Pico W to WiFi, serve a responsive control page, switch an LED and display the onboard temperature or an external sensor, with timeouts and reconnect handling.
Raspberry Pi Pico Oscilloscope with MicroPython
Convert a Raspberry Pi Pico into a basic 500 kSPS oscilloscope using its 12-bit ADC and MicroPython. Displays waveforms on an SSD1306 OLED or streams samples over USB serial to a Python plotter on your PC.
Self-Hosted Nextcloud NAS on Raspberry Pi 4
Build a private, durable Nextcloud NAS on a Raspberry Pi 4 -- SSD boot instead of a failure-prone SD card, Docker Compose with Redis caching, Tailscale for remote access with zero ports forwarded, and an automated backup strategy that actually runs.