USB 3.0 Ammeter Based on PY32 and INA219
1. Project Introduction
The PY32F002A is a cost-effective 32-bit MCU, with some packages starting at just 0.3 RMB, suitable for various low-cost embedded applications. This project implements a USB 3.0 ammeter based on the PY32F002A and INA219 current sensor, capable of measuring the current, voltage, and power of USB 3.0 devices.
2. Functional Characteristics
Measurement range: 3.3V ~ 20V, 0 ~ 5A
Current, voltage, and power are displayed on the screen.
Data can be output via serial port.
Both Type-A and Type-C versions are
available. All USB 3.0 high-speed signal lines are connected, supporting high-speed transmission and fast charging protocols (actually tested to achieve a transmission speed of 340 MB/s and drive a 4K 60Hz display).
3. Hardware Design
The main chips used are as follows:
PY32F002A: 32-bit MCU, 20KB Flash, 4KB RAM, 24MHz clock speed;
INA219: 12-bit ADC, current sensor, I2C interface;
LGS5148: Wide input voltage, adjustable output Buck step-down chip;
XC6206: 200mA low dropout regulator;
SSD1306: 128x32 OLED display.
Type-A interface uses a recessed package;
Type-C interface uses a 0.8mm thick clip-on package.
4. Notes:
Considering impedance matching for high-speed signals, both versions use a four-layer board.
Type-A version uses a 1.6mm thick board, JLC04161H-3313 impedance;
Type-C version uses a 0.8mm thick board, JLC04081H-3313 impedance (0.8mm thick board can use a gold-plated immersion resistor).
R1 is the sampling resistor for INA219; a 2mΩ resistor is recommended to reduce voltage drop, but a 10mΩ resistor or larger can also be used. Using other resistance values requires modifying the current calculation formula in the program.
You can purchase a 5W USB resistor load to calibrate the readings by modifying the value of `CURRENT_CALIBRATION` in `main.c`.
The BOM exported by LCSC EDA is correct.
The serial port and SWD debugging interface are already exposed; you can use a DAPLink-compatible debugger for downloading and debugging.
When the Type-C version is powered from the female port, the reading will include the ammeter's own current; you can modify the program to subtract this current.
5. The attached images



include source code and a directly programmable hex file.