Files
battery-monitor/STORY.md
denq 172eb6b046 Fix image caption formatting - add blank lines for proper display
Added blank lines between images and captions to ensure captions appear
on a new row below images instead of on the same line.

This follows Markdown best practices where a blank line creates a new
paragraph for the caption text.

Fixed in both STORY.md and STORY.zh-CN.md for all images.
2025-11-06 17:51:24 +08:00

11 KiB

Solving uConsole's 4G Module Mystery: A Vibe Coding Story

Part of the "Vibe Coding for Work/Life" series — Real stories of building custom solutions anywhere, using portable devices and modern tools to solve everyday problems.

When Your Computer Becomes Its Own Debug Environment

Imagine debugging a device's power management issues while lounging in a coffee shop, building the diagnostic tools directly on that same device. No desktop workstation. No "I'll fix this when I get home." Just you, a pocket-sized computer, and the freedom to solve problems wherever inspiration strikes.

This is how I spent one weekend solving the uConsole CM5's notorious 4G module hang issue—and discovered it wasn't about power delivery at all. It was about voltage drop.

The Problem: When 4G Kills Your System

The ClockworkPi uConsole is a hacker's dream: a Raspberry Pi CM5 squeezed into a clamshell form factor with a mechanical keyboard and modular expansion bays. It's the kind of device that makes you want to tinker, customize, and push boundaries.

But there was a frustrating catch. Enable the 4G expansion module on battery power, and the system would randomly freeze—dead in its tracks. The only fix? Physical battery removal and restart.

Forum threads filled with theories:

  • "It's buggy software"
  • "Your batteries are fake"
  • "The power management IC can't deliver enough watts"
  • "You need to buy better batteries"

None of these explanations felt complete. Users were stuck choosing between mobility (battery power) and connectivity (4G), but never both reliably.

I decided to investigate—but here's the twist: I'd build all the diagnostic tools on the uConsole itself, while running on battery power. If I could solve the problem using the very device experiencing it, that would prove something profound about modern development workflows.

Debugging the 4G modem issue on uConsole itself

Building the solution on the device experiencing the problem—true vibe coding in action

The Investigation: Following the Voltage

Sitting at a coffee shop, uConsole on battery, I started building. First, a simple web app to monitor battery metrics in real-time. Next.js hot reload meant I could see changes instantly. No compile times, no deployment steps—just pure, iterative problem-solving.

The monitoring revealed something unexpected. When the 4G module was active:

  • Power consumption looked normal (~8-10W)
  • Current draw spiked during transmission (up to 2A)
  • But voltage... voltage was dropping dangerously low

The Breakthrough: It's Not Watts, It's Volts

A few hours of datasheets later, the picture became clear:

The SimTech SIM7600G-H 4G module has strict voltage requirements:

  • Operating range: 3.4V to 4.2V
  • Minimum safe voltage: ~3.45V
  • Current draw: Up to 2A during transmission bursts

What happens when voltage drops below 3.45V:

  1. 4G module browns out
  2. USB bus hangs
  3. System becomes unresponsive
  4. Only battery removal resets it

The real problem: Lithium-ion batteries have internal resistance. When the 4G module draws 2A, voltage sags momentarily. If the battery is already partially discharged or has high internal resistance, voltage drops below 3.45V → instant hang.

This explained everything:

  • Why USB power helps (reduces battery current draw)
  • Why some batteries work better (lower internal resistance)
  • Why it happens randomly (depends on battery state and load timing)

The Insight: Not All Battery Capacity Is Usable

The breakthrough came from building a new visualization: Battery Energy Output vs. Voltage—a discharge curve that plots remaining capacity against voltage.

I ran a complete test with FEB-4000 4000mAh batteries (100% to ~2%), capturing 4,318 data points over 2 hours 48 minutes:

Energy Output vs Voltage with 3.45V Threshold

The red line shows the 4G module's minimum voltage. Everything to the right is unusable for 4G connectivity.

The shocking result:

  • Total battery capacity: 24.79 Wh
  • Usable capacity above 3.45V: 13.39 Wh (54%)
  • Unusable below 3.45V: 11.40 Wh (46%)

This means: You can only use about half your battery capacity for reliable 4G operation. Once voltage drops to 3.45V, you still have 40-50% charge remaining—but it's unusable for 4G.

The Solution: Voltage-Aware Power Management

With the root cause identified, the fix became obvious: reduce current draw when 4G is active to prevent voltage sag.

The strategy:

  • Detect when 4G module is active (modem state, network traffic)
  • Reduce CPU frequency from 2.4GHz to 1.8GHz
  • Lower current draw = less voltage sag
  • Keep voltage above 3.45V threshold

Result: Rock-solid 4G operation on battery power.

Why Vibe Coding Works: The Magic of Zero Context Switching

Here's what blew my mind: this entire project—from "why does this crash?" to "production-ready solution with automated power management"—took about 10 hours across two days.

No desktop workstation. No oscilloscope. No separate test device. Just:

  • The uConsole itself
  • A web browser for research
  • Claude Code for AI-assisted development
  • Coffee shop WiFi

The secret sauce:

  1. Immediate Feedback Loop: Build a chart → Watch it live → Spot the voltage drop → Fix it → Repeat
  2. Zero Context Loss: The debugging environment IS the target environment
  3. Modern Tooling: Next.js hot reload, TypeScript safety, AI-assisted coding
  4. Location Independence: Coffee shop → Park bench → Train ride → Couch
  5. Constraint-Driven Design: Limited resources force elegant solutions

The workflow becomes circular:

Observe issue → Research → Prototype → Test → Iterate
           ↑_____________________________________|
              All on the same device, anywhere

This isn't just faster—it's more fun. Pure flow state, building exactly what you need, exactly when you need it.

What This Means: The Democratization of Problem-Solving

Ten years ago, solving this would have required:

  • An engineering lab
  • $5,000+ of test equipment
  • Cross-compilation toolchains
  • Days of setup time
  • Dedicated workspace

Today? A $200 pocket computer and one focused weekend.

This isn't just about professional developers. Vibe coding opens doors for:

  • Hobbyists building battery-powered projects
  • EV enthusiasts testing battery performance
  • Field researchers debugging equipment on-site
  • Makers troubleshooting hardware in real-time
  • Students learning by building actual tools

The barrier to "scratch your own itch" development just collapsed.

The Battery Selection Problem Nobody Talks About

Users select batteries based on:

  • Capacity (mAh) alone
  • Price
  • "Recommended" lists

They should be selecting based on:

  • Continuous Discharge Rate (CDR): 15A minimum
  • Internal Resistance: Lower = better voltage stability
  • Voltage retention under load: Measured, not guessed

The discharge curve visualization I built becomes a battery rating tool. Test your batteries, see how much usable capacity you actually have above 3.45V, make informed decisions.

Recommended batteries for 4G:

  • Samsung 25R (2500mAh, 20A CDR) - Excellent voltage stability
  • Samsung 30Q (3000mAh, 15A CDR) - Good balance
  • Sony VTC6 (3000mAh, 15A CDR) - Superb under load
  • LG HG2 (3000mAh, 20A CDR) - Best voltage retention

Avoid generic/unbranded cells with <10A discharge rating—they'll hit 3.45V early.

Try It Yourself

The entire solution is open source (GPL v3):

Repository: battery-monitor on Gitea

Quick Start:

git clone https://hiwifi.denq.us:8418/denq/battery-monitor.git
cd battery-monitor
npm install
npm run dev  # Visit http://localhost:3000

# Install uConsole Smart Power Regulator (optional)
cd scripts
sudo ./install-uconsole-power-regulator.sh install

What you get:

  • Real-time battery voltage/current/power monitoring
  • Battery Energy Output vs. Voltage discharge curve
  • 3.45V threshold visualization for 4G compatibility
  • Intelligent power regulation (AC detection + 4G state monitoring)
  • Automatic voltage alerts when battery + 4G active
  • Session recording and CSV export
  • Complete battery testing toolkit

Want detailed usage guide? See TOOL-GUIDE.md

The Joy of Building

There's something profoundly satisfying about identifying a problem on a device and building the solution on that very device. No "I'll fix this later." No context switching. Just pure, focused problem-solving in the moment.

The uConsole CM5 now runs stably on battery with 4G active. The community has a new understanding of why some batteries work better than others. And the entire solution was built in one focused weekend of vibe coding.

This is vibe coding: Building custom solutions with joy, anywhere inspiration strikes. Not because you have to, but because you can.

The tools are here. The hardware is affordable. The only question is: what will you build?


Community Impact

Since sharing this discovery:

  • Multiple users confirmed voltage drop as root cause
  • Battery recommendations refined based on discharge testing
  • uConsole Smart Power Regulator adopted by several users
  • New battery test methodology for community
  • Event-driven AC detection added based on user feedback

Share Your Results:

  • Test your batteries with the discharge curve tool
  • Share findings in ClockworkPi forums
  • Help build community battery database

Questions? Contributions?


This story is part of the Vibe Coding Chronicles series, documenting real projects built entirely on portable devices. Follow along as we explore what's possible when development becomes truly mobile.

Tags: #uConsole #VibeCoding #4GModule #BatteryAnalysis #PortableComputing #AIAssistedDevelopment

Next in series: Building a mesh network monitor while hiking remote trails


Technical Summary

Root Cause: Battery voltage drops below 3.45V under 2A load from 4G module → brownout → system hang

Solution: CPU frequency scaling when 4G active → lower current → stable voltage

Key Discovery: ~50% of battery capacity unusable for 4G due to voltage requirements

Tool Created: Real-time battery monitor with discharge curve analysis for voltage-based battery rating

For complete technical documentation: TOOL-GUIDE.md


License: GPL v3 (same as uConsole hardware designs)