Building Spark Analyzer: A $50 USB-C Power Lab
How I built an ESP32-powered USB-C PD analyzer and programmable power supply - because commercial options shouldn't cost $200+

Building Spark Analyzer: A $50 USB-C Power Lab
Every USB-C project I've worked on hit the same wall: I couldn't see what was happening.
Which voltage did the charger negotiate? Did my sink request get accepted? Why does this work with Charger A but not Charger B? Commercial USB-C analyzers exist, but they're $200+ and often just show you data without letting you control anything.
I wanted something different: a tool that lets me see USB-C PD negotiations AND actively control power delivery. So I built one.
What Spark Analyzer Does
Think of it as a USB-C power lab in your pocket:
Analysis Mode:
- Real-time voltage and current monitoring (±10mV, ±20mA)
- PD negotiation packet capture
- Source capability enumeration
- Contract verification
Control Mode:
- Request any voltage the charger supports (5V, 9V, 12V, 15V, 20V)
- Fine-grained control with PPS (20mV steps)
- Programmable current limits
- Output enable/disable
Interface:
- Web-based dashboard (WiFi)
- Mobile-friendly design
- REST API for automation
- BLE for basic control
The Design
At its core, Spark Analyzer connects three chips:
USB-C PD Controller → ESP32-C3 → Current Monitor
(FUSB302) (brain) (INA228)
│ │
└────────────────────────┼──────────────────┘
│
Buck-Boost
Converter
│
Output Port
The PD Controller (FUSB302)
The FUSB302 handles all USB-C Power Delivery communication:
- Monitors CC lines for cable attachment
- Decodes PD messages from the charger
- Encodes our requests
- Reports negotiation status
I talk to it over I2C from the ESP32.
The Brain (ESP32-C3)
The ESP32-C3 runs the show:
- PD state machine (attachment, negotiation, contract management)
- Web server for the dashboard
- BLE GATT server for mobile control
- Power monitoring and safety checks
Why C3? It's cheap (~$2), has WiFi and BLE, and the single core simplifies timing. For a tool that's always plugged in, the C6's power optimization features aren't needed.
The Monitor (INA228)
The INA228 is a Texas Instruments power monitor with a 20-bit ADC. It measures:
- Bus voltage (what's actually on the output)
- Shunt voltage → current (via 10mΩ resistor)
- Power (voltage × current, calculated on-chip)
- Energy (accumulated power over time)
This isn't just nice data to have - it's critical for safety. If we're drawing more current than negotiated, we need to know immediately.
Key Technical Decisions
Power Path Design
USB-C PD can deliver up to 100W. Handling that safely required careful design:
Input protection: TVS diodes clamp voltage spikes, fuse limits fault current.
Current sensing: High-side sensing via INA228 catches all load current, not just some paths.
Output control: A load switch lets us disconnect the output independently of PD negotiation. If something goes wrong, we cut power fast.
PD Timing
USB-C PD has strict timing requirements - responses must happen within milliseconds. This drove several firmware decisions:
FreeRTOS task priorities: PD handling runs at high priority to meet response deadlines.
Interrupt-driven messages: The FUSB302's INT pin triggers immediate attention, not polling.
State machine discipline: Every state has a timeout to prevent getting stuck.
Noise Management
Switching regulators and WiFi radios don't naturally coexist with precision ADCs. I dealt with this through:
Physical separation: Digital and power sections have distinct PCB regions.
RC filtering: Simple filters on ADC inputs remove high-frequency noise.
Software averaging: Multiple samples combined for displayed values.
Timing coordination: Critical measurements happen during WiFi idle periods when possible.
The Web Interface
I wanted the interface to work on any device - laptop, phone, tablet. A responsive web dashboard was the obvious choice.
Real-time updates: WebSocket connection pushes voltage, current, and power readings at 10Hz.
Control panel: Buttons to request different voltages, enable/disable output, set current limits.
PD status: Shows current contract, available PDOs, negotiation history.
Mobile-friendly: Touch targets sized for fingers, layout adjusts to screen size.
No app to install. Just connect to the Spark Analyzer's WiFi or access it on your local network.
What I Learned
USB-C PD Is Simpler Than It Looks
The PD specification is intimidating (hundreds of pages), but the core flow for a basic sink is straightforward:
- Detect attachment
- Wait for Source_Capabilities message
- Parse available voltages
- Send Request for desired voltage
- Wait for Accept
- Wait for PS_Ready
- Power is available
Most complexity is in edge cases and error handling. For a benchtop tool, you can start simple and add robustness incrementally.
Thermal Management Matters
At 20V and 3A, we're moving 60W. Even with good efficiency, several watts become heat.
I underestimated this initially. The first prototype would thermal throttle after 5 minutes of heavy use. Adding copper area and thermal vias fixed it.
WiFi and USB-C Can Coexist
I was worried about interference between WiFi and the precision measurements. In practice, with decent layout and filtering, it's fine. The noise floor increased slightly, but not enough to affect useful measurements.
Results
The final product exceeds what I originally needed:
| Spec | Value |
|---|---|
| Voltage accuracy | ±10mV |
| Current accuracy | ±20mA |
| PD negotiation success | 99.8% (tested with 50+ chargers) |
| Web interface latency | <50ms |
| Price | ~$25 BOM, $49.99 assembled |
More importantly, it actually helps me understand USB-C PD in my projects. When something doesn't work, I can see exactly why.
Get One
Build it yourself: Everything is open source at github.com/tooyipjee/sparkanalyzer2. KiCad files, firmware, web interface - all there.
Buy assembled: Available in my store for $49.99. Tested and ready to use.
What's Next
Future improvements I'm considering:
- Cable e-marker reading: Identify cable capabilities
- Programmable profiles: Save and recall common configurations
- Data logging: Export power traces for analysis
- Oscilloscope triggering: Sync with scope captures
Learn More
If you want to understand the USB-C PD protocol in detail:
- USB-C PD Tutorial with ESP32 - Step-by-step implementation guide
- Building the Stepper Driver Version - Adding motor control
Questions about Spark Analyzer or USB-C PD in general? Reach out via the contact form.