Building an LLM Robot with My Son — EP 7. Upgrading the Robot Brain from Arduino to Raspberry Pi

Building an LLM Robot with My Son — EP 7. Upgrading the Robot Brain from Arduino to Raspberry Pi

Arduino had reached its limit.

The setup from EP 6 — Arduino plus a Python bridge laptop — worked, but it meant the robot was physically tethered to a laptop by a USB cable. An "autonomous" robot on a leash felt wrong. Migrating to Pi would let the bridge and ROS2 nodes run inside the robot itself. True independence.

Also, my son had been asking about this for weeks. "When does the real computer go in?" had been the recurring question. The time had come.


Pi 4 vs Pi 5 vs Banana Pi

Three options, one criterion: LLM doesn't run on the Pi. The Pi handles ROS2 nodes, camera pipeline, and bridge role only. Heavy inference stays on the Mac LLM server.

Device Approx. price RAM USB 3.0 Thermals Notes
Raspberry Pi 4B 4GB $55 4GB 2 ports Hot Widely available
Raspberry Pi 5 4GB $60 4GB 2 ports Better Stock inconsistent
Banana Pi M5 $45 4GB 4 ports Moderate ROS2 support uncertain

Pi 5 is 2–3x faster in CPU performance than Pi 4. Running the camera pipeline (640×480 30fps JPEG encoding) on Pi 4 consumed 40–60% CPU. On Pi 5 it drops under 20%. Multiple ROS2 nodes running simultaneously showed stuttering on Pi 4 in testing.

I wanted Pi 5. Stock issues made me pause, and I went with Pi 4B 4GB — available immediately and sufficient for our use case. Pi 5 is the upgrade when we move to season 2.

Banana Pi: I tested ROS2 installation directly, but sparse community support led to dependency conflicts I didn't want to spend time untangling. Eliminated.


The Day My Son Took Over Hardware

When the Pi arrived, I handed it to him. "Mount it on the robot."

For real.

Up to now, even though my son was "in charge of hardware," I'd been heavily involved alongside him. This time I stepped back and let him go.

He held the Pi and studied it. Saw the 40 GPIO pins. "What are all of these?" I printed out a pinout diagram. "Work from this."

Mounting the Pi to the chassis went fine. M2.5 screws and standoffs — once I explained the concept, he handled it.

The power wiring was where things went wrong.


The Wiring Mistake That Almost Killed the Pi

He pulled the 5V pin from the L298N motor driver and connected it to the Pi's GPIO 5V pin. The logic: "5V goes to 5V."

Wrong. The 5V from L298N is regulated from the motor battery — connecting it directly to the Pi GPIO 5V pin bypasses the official power input (USB-C) and feeds power through a path the Pi doesn't expect. Voltage stability isn't guaranteed. In the worst case, the board gets damaged.

I caught it before he connected it. "Hold on — let's check that before you plug it in."

We looked at the pinout together. GPIO 5V pins can be both input and output. The Pi always needs power through its official port. L298N 5V to GPIO direct is how boards get fried. I walked him through it.

After thinking: "So motor power and Pi power have to be separate?" Yes. Separate power bank for Pi USB-C, separate Li-Po for motors.

After that, he checks with me before connecting any power line. A rule he made for himself.


Migration: What Changed

Switching from Arduino to Pi, the differences:

Changed:
- Motor driver control: digitalWrite/analogWriteRPi.GPIO or gpiozero
- Ultrasonic sensor: NewPingRPi.GPIO.pulse or adafruit-circuitpython-hcsr04
- Serial bridge: Pi itself handles it, no laptop needed
- ROS2 nodes: now run directly on Pi

Unchanged:
- Pin assignments (CLAUDE.md update only)
- LLM server communication structure (WebSocket)
- Bridge code logic (Python, only port numbers changed)

New section added to CLAUDE.md for Pi:

## Hardware (current: Raspberry Pi 4B)
### Pin Map (BCM numbering)
| Component | BCM Pin | Notes |
|-----------|---------|-------|
| L298N IN1 | 17 | Left motor direction A |
| L298N IN2 | 27 | Left motor direction B |
| L298N ENA | 18 | Left motor PWM (HW PWM) |
| L298N IN3 | 22 | Right motor direction A |
| L298N IN4 | 23 | Right motor direction B |
| L298N ENB | 13 | Right motor PWM (HW PWM) |
| HC-SR04 Trig | 24 | |
| HC-SR04 Echo | 25 | 3.3V level (Pi GPIO) |

### Important
- HC-SR04 outputs 5V; Pi GPIO tolerates only 3.3V
- Echo pin needs voltage divider or level shifter (using 4.7kΩ + 10kΩ divider)
- ENA, ENB assigned to HW PWM-capable pins (18, 13)

The HC-SR04 echo voltage issue was a new wrinkle. HC-SR04 runs on 5V and its echo output is 5V — directly connecting to Pi GPIO (3.3V max) risks damage. Arduino (5V IO) had no issue with this. Pi requires a voltage divider.

Explaining voltage dividers to my son: I'm not sure he fully grasped it from the explanation. When I said "two resistors split the voltage," his expression said "I'll take your word for it." But when I had him actually put one together on a breadboard and measure both sides with a multimeter — "oh, it actually goes down" — that's when it clicked. He needs to see it to believe it.


First Time It Ran on Pi

ROS2 installed, nodes launched, bridge script running. First time Pi connected to the LLM server:

[robot_bridge] LLM server connected: ws://192.168.1.100:8765
[sensor_node] HC-SR04 initialized (Trig:24, Echo:25)
[motor_node] L298N initialized
[robot_bridge] Transmitting sensor data...

The robot moved around the living room. No laptop cable. Just a power bank and the Pi on board.

My son watched it. "Now it's a real robot."

He was right. Before this, it was technically functional but physically constrained. Now it was different.


Battery Life

Measured with Li-Po 3S 2200mAh, two motors running:

  • Motors only (no LLM communication): ~45 minutes
  • Full operation with LLM communication: ~32 minutes
  • Pi + LLM comm, motors stopped: ~2 hours

LLM communication consumes more battery than expected — sustained WiFi connection and data transfer add CPU load. 32 minutes is sufficient for testing and demonstrations but short for extended operation. Options going forward: larger battery, or reducing LLM query frequency.

댓글

이 블로그의 인기 게시물

개발자는 코드를 쓰는 사람이 아니다 — AI 시대에 남는 자리는 '책임'에 있다

Harness Engineering in Practice — How Anthropic Designs AI Agents

What Is Harness Engineering — Designing the Reins for AI Agents