Skip to the content
PCBKitNew board
2 layers30 × 25 mmServo controller, the printed circuit board in 3D

Servo controller

ghemyn/picar1

Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

Size
30 × 25 mm
Copper layers
2
Thickness
1.6 mm
Parts
8
Nets
16
Pads
35
Tracks, vias
62, 1
Routed
Yes
KiCad
KiCad 8.0 (file 20240108)
Created
28 Apr 2025
Updated
24 Jul 2026

Overview

Servo controller is an open-source printed circuit board by ghemyn, from the ghemyn/picar repository on GitHub, published under the MIT licence. It is a 2-layer board of 30 × 25 mm with 8 parts on 16 nets, routed with 62 tracks and 1 via.

Its parts include 3 connectors, 2 capacitors, 1 resistor, 1 IC and 1 switch. It belongs with the robots and motor control boards and the RISC-V boards of this library.

README

README.md

picar

Car with autonomous and remote-controlled capabilities controlled by Raspberry Pi 5 and a CH32V003 microcontroller. Features a custom made mainboard PCB responsible for controlling motors, servos and delivering power to the RPi 5.

It is capable of real-time remote control with a gamepad (e.g. XBox One gamepad) alongside a live WebRTC stream from its camera. Moreover, simple autonomous driving is possible by following an RGB tracking marker.

Version 3 Early (still the old frame from V2)

picarV3early1 picarV3early2

PiCar with the tracking marker next to it

Future ideas

  • Add a ToF sensor and use it in tandem with the DepthAnything V2 depth estimation model to acquire real (approximated) depth information from the camera.

Hardware

  • Battery pack composed of 3x 18650 cells connected in series. It has both XT60 connector for the main power and 4-pin JST-XH used for balancing.
  • SG92R micro servo used for steering
  • Raspberry Pi 5 8GB
  • Raspberry Pi Camera HD v2 8MPx
  • Custom PCB mainboard responsible for controlling motors, servos and delivering power to the RPi 5. (More on that below)
  • Custom 3D-printed frame and steering system (files available in the "designs" directory)
  • 4x 60x8mm black Pololu 1420 wheels
  • 2x 6x13x5mm bearings for the front wheels
  • 2x N20-BT07 micro 100:1 320RPM 12V motors
  • M3 screws used for assembling the frame and wheels together

PCB mainboard

schematic

/pcb_main_board/pcb_main_board_schematic.svg

render

/images/pcb_main_board1.png

On-board microcontroller

ch32v003

CH32V003 MCU is the main controller of the whole board. It is responsible for controlling the motor drivers, servo motors and monitoring the battery voltage. It communicates with the Raspberry Pi 5 over I2C.

Battery to RPi 5 voltage step-down

mp2338

The battery input voltage is first filtered by the input low-ESR capacitor and capped to 15V by a SMBJ15A TVS diode. Then the MP2338 IC is used to reliably step-down the battery voltage from 9V-12.6V range to ~5.1V that is then connected via a USB-C cable to the RPi 5. The MP2338's GND pin is connected to wide copper traces with vias in order to improve cooling.

Motor control

motors

TB6612FNG IC is used to drive both of the main motors. The IC logic is driven by PWM signals generated by the on-board microcontroller. The PWM frequency can be adjusted from the software layer if the user wants to prioritize peak power or to minimize the audible switching noise. The lower the frequency, the more efficient the motors are, but the louder they become.

Servo control

servo

The mainboard is capable of running 4 separate hardware PWM signals at once which are generated by the on-board microcontroller. The servo motors are powered with 4.8V generated by another MP2238 IC configured in the same way as the other one used for powering RPi 5, except for the output voltage. The servo section also has a 3-pin header for each signal channel in order to simplify the connections. There are more servo channels than are currently needed for future-proofing reasons. e.g. allowing the camera to have adjustable yaw and pitch in the future.

Wheels

The front wheels are fastened to their mounts with short M3 screws. Those mounts then clip into the ball bearings, working similarly to LEGO Technic connections. A pin with the correct diameter and side cuts is pushed into the bearing hole and holds firmly enough for normal operation. The rear wheels are press-fitted onto the motor shafts:

frontandback

Front wheel assembly disassembled in Fusion 360:

frontwheelassembly

Software and control

Frontend

PiCar can be controlled through a simple Websockets-based web interface (/car/software/index.html). When you run the Python "Remote Control" main loop an HTTP server starts up and reveals the visual interface at http://{raspberry_pi_5_ip}:8000. There are two sliders that control it but the better (and way cooler) option is to use a gamepad and control the car this way. The website automatically detects connected gamepads and lets the user steer by using both triggers for accelerating and braking and the left thumbstick for steering. It is also possible to set the motors PWM switching frequency.

frontenddemo

There also is a viewport for watching the live feed coming from the camera connected to the RPi 5. The stream source must be a WebRTC source which can be created easily by using MediaMTX. You can find the working mediamtx.yml file I use to enable the stream at /car/mediamtx.yml. Once mediamtx starts with my provided config, the camera can be accessed by connecting via WebRTC to {raspberry_pi_5_ip}:8889/rpi.

Vision

Autonomous driving, for now, is a simple computer vision algorithm that searches for a special marker with three key colors: red, green, and blue on the live feed streamed from the Raspberry Pi Camera HD v2 8MPx.

The camera feed is first filtered bilaterally to remove small details and noise in the subsequent marker search. Then gamma is adjusted to increase contrast, and the resulting image is binarized so that the SimpleBlobDetector from the OpenCV library can detect three circles. Finally, the algorithm checks whether the circles are "inside" the potentially found marker—i.e., whether they are not shifted from the averaged center by more than one standard deviation. If they are not, we can be certain that the marker has been found.

Below is a visualization of how the marker is seen by the algorithm:

MarkerDetection

When the marker is found, the vehicle drives forward and turns so that the center of the marker aligns with the center of the camera's view. This is sufficient to effectively track the marker.

Future Vision Enhancement

I plan to use a ToF distance sensor in tandem with the computer vision model DepthAnythingV2, which estimates depth using a single camera. This combination will allow me to acquire approximate (yet sufficiently accurate) distance information of everything visible in the front camera. This data will enable shape detection by contours and autonomous obstacle avoidance.

Firmware

The CH32V003 microcontroller runs a firmware that acts as a PWM and motor control interface for the Raspberry Pi 5. The firmware exposes a register-based interface over I2C using slave address 0x17, allowing the RPi to elegantly control all aspects of motor and servo operation.

I2C Communication Protocol

The firmware operates as an I2C slave that receives write-only commands structured as [register_id, data_low, data_high]. Each register controls a specific aspect of the system:

RegisterPurposeRange
1TIM1 (servo) frequency1 - 48000 Hz
2TIM2 (motor) frequency1 - 48000 Hz
4-7Servo CH1-CH4 duty cycle0 - PWM_PERIOD(1000)
10-11Motor PWM (right/left) duty cycle0 - PWM_PERIOD(1000)
12Motor direction controlBit 0: DIRF, Bit 8: DIRB

Building the code

RPi 5 Python

Configure the virtual environment if you need and run pip install -r requirements.txt while being in the /car/software directory to download the necessary packages. Downlaod opencv as a standalone package. Once everything is downloaded, run python main.py and it should work fine.

Enabling the necessary RPi 5 options

To make I2C communication work properly, enable it either with the raspi-config command or by manually adding the necessary lines to the /boot/firmware/config.txt file:

text
dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=80000 # or any other as you wish
dtparam=i2s=on

Also enable the camera detection in the same way. Here is the line for /boot/firmware/config.txt:

text
camera_auto_detect=1

CH32V003 C Firmware

Downloading and building it through MounRiver Studio IDE is the easiest route to go. This repo already has project files that work out of the box when you open them with the IDE. Just press F7 and it should build perfectly fine.

Flashing it

You'll need a WCH LinkE programmer in order to flash the firmware to the chip. Once you have it, connect GND to GND and the SWDIO pin to the chip's SWIO pin according to its datasheet (It's pin PD1 for CH32V003A4M6). The chip must be powered either from the programmer's voltage pin or externally during flashing.

Now go to MounRiver Studio IDE and press F7 to build your project and then F8 to flash it having the WCH LinkE programmer plugged into your computer at the same time, note that flashing your code does not rebuild it automatically, you have to remember to press F7 each time.. You can also change the flashing configuration but it's almost always good to go by default. (called Download Configuration):

wchlinke

Do not press or hold the reset button during flashing (the NRST pin)

Archive

Take a look at the PROGRESS.md markdown file to see how the project evolved over time.

Parts

8
QtyValueFootprintReferences
1100nCapacitor_SMD:C_0805_2012MetricC2
110kResistor_SMD:R_0805_2012MetricR1
110uCapacitor_SMD:C_0805_2012MetricC1
1CH32V003AxMxPackage_SO:SOP-16_3.9x9.9mm_P1.27mmU1
1Conn_01x02_SocketConnector_PinSocket_2.54mm:PinSocket_1x02_P2.54mm_VerticalJ3
1Conn_01x03_SocketConnector_PinSocket_2.54mm:PinSocket_1x03_P2.54mm_VerticalJ1
1Conn_01x04_PinConnector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_VerticalJ5
1SW_PushButton_Switch_THT:SW_PUSH_6mmSW1

Questions

How big is the Servo controller PCB?

It measures 30 × 25 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Servo controller use?

8 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Servo controller KiCad files?

From the ghemyn/picar repository on GitHub, at the commit this page was made from: the board is OLD_pwm_board/design/servo_controller.kicad_pcb and its schematic OLD_pwm_board/design/servo_controller.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Servo controller design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).

More from ghemyn/picar

2
  • 2 layers90 × 137.5 mmPcb main board, the printed circuit board in 3D

    Pcb main board

    ghemyn/picar

    Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

    76 parts1MIT
  • 2 layers85 × 56 mmPcb main board, the printed circuit board in 3D

    Pcb main board

    ghemyn/picar

    Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

    72 parts1MIT

Similar boards

  • 2 layers20.5 × 24.8 mmPi interface, the printed circuit board in 3D

    Pi interface

    opulo-inc/lumenpnp

    The LumenPnP is an open source pick and place machine.

    8 parts3.7k
  • 2 layers59.9 × 25.7 mmBuffer, the printed circuit board in 3D

    Buffer

    hoglet67/RGBtoHDMI

    Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI

    8 parts1kGPL-3.0
  • 2 layers52 × 12.6 mmUSB, the printed circuit board in 3D

    USB

    shanteacontrols/OpenDeck

    A platform for building interactive control and sensing devices using MIDI and OSC built with Zephyr RTOS.

    8 parts960Apache-2.0
  • 2 layers87.5 × 48.5 mm7 input macropad, the printed circuit board in 3D

    7 input macropad

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    8 parts915
  • 2 layers36.2 × 63.1 mmPicoMemcard pico, the printed circuit board in 3D

    PicoMemcard pico

    dangiu/PicoMemcard

    Emulating PSX Memory Card (or controller) using a Raspberry Pi Pico

    8 parts694GPL-3.0
  • 2 layers36 × 10 mmPCB4-PWR BTN Rev.A, the printed circuit board in 3D

    PCB4-PWR BTN Rev.A

    OLIMEX/DIY-LAPTOP

    Do It Yourself Open Source Hardware and Software Modular Hacker's Friendly Laptop

    8 parts578Apache-2.0