Skip to the content
2 layers81.8 × 81.8 mmPeter pan, the printed circuit board in 3D

ESP32 quadcopter flight controller (X frame), flown over WiFi from a PC with a PS4 gamepad. The repository holds two parts:

Size
81.8 × 81.8 mm
Copper layers
2
Thickness
1.6 mm
Parts
24
Nets
34
Pads
83
Tracks, vias
77, 16
Pours
1
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
24 Sep 2026
Updated
27 Sep 2026

Overview

Peter pan is an open-source printed circuit board by pierre-bouckson, from the pierre-bouckson/peter_pan repository on GitHub. It is a 2-layer board of 81.8 × 81.8 mm with 24 parts on 34 nets, routed with 77 tracks and 16 vias.

It is built around the R-78E3.3-0.5, ERJ3GEYJ103V and VJ0603V104ZXAPW1BC, with the M20-7821546 among its other parts. Its parts include 7 connectors, 4 capacitors, 3 resistors and 1 IC.

Main components

4

README

README.md

peter_pan

peter_pan drone

ESP32 quadcopter flight controller (X frame), flown over WiFi from a PC with a PS4 gamepad. The repository holds two parts:

FolderContent
firmware/PlatformIO / Arduino-ESP32 firmware running on FreeRTOS
python_tool/PC-side tools: gamepad pilot with live PID tuning, ESC calibration
PCB/KiCad 9 carrier board (schematic, layout, libraries, JLCPCB files)
text
 PS4 gamepad ──USB──► PC (gamepad_pilot.py) ──UDP 8889──► ESP32 (WiFi AP "peter_pan")
                            ▲                                  │
                            └──── UDP 8894 telemetry ◄─────────┤
                            └──── UDP 8895 debug     ◄─────────┘

Hardware

Parts list

QtyPartReference
1FrameHAWK'S WORK F450, 450 mm, with standard landing gear
4MotorsHAWK'S WORK 2212 920KV brushless, 2–4S (2 × CW + 2 × CCW)
4ESCsRUIZHI 40A brushless ESC, 2–4S, BEC 5V/3A
1 setPropellersTbest self-locking propellers, CW/CCW, 8-piece set
1BatteryTattu LiPo 3S 11.1 V 2300 mAh 45C
1ChargerHaisito B3 LiPo charger, 2S/3S
1Flight controllerESP32 DevKit V1 (30 pins) on the custom carrier board (see PCB)
1IMUST LSM6DSOX (LSM6DSOTR), soldered on the PCB
1RegulatorRECOM R-78E3.3-0.5, soldered on the PCB
8ScrewsM2.5, to mount the PCB on the frame
1GamepadSony PS4 DualShock 4, USB

Wiring summary

PartDetail
MCUESP32 DevKit (esp32dev)
IMULSM6DSOX (accelerometer + gyroscope) on I2C, SDA = 21, SCL = 22
Motors4 ESCs, servo-style signal 1000–2000 µs at 400 Hz
Motor pinsM1 = GPIO 13, M2 = GPIO 33, M3 = GPIO 23, M4 = GPIO 15
Status LEDGPIO 2 (off = motors cut by stop / emergency)

M1/M2 are on the right side, M3/M4 on the left. M1 and M3 spin counter-clockwise (see YAW_DIR in firmware/lib/control/flight_controller.h).


PCB

Custom 2-layer carrier board (KiCad project in PCB/, fabrication files for JLCPCB included). On board:

  • ESP32 DevKit V1 socket (2 × 15-pin female headers)
  • RECOM R-78E3.3-0.5 DC/DC regulator: battery → 3.3 V for the ESP32 and the IMU
  • LSM6DSOX IMU on I2C (SDA = GPIO 21, SCL = GPIO 22)
  • 4 ESC headers (PWM / 3.3 V / GND) and a 2-pin battery input

⚠️ The middle pin of the ESC headers is the 3.3 V rail: leave the red (BEC 5 V) wire of the ESC cables disconnected. The PCB header numbers do not match the firmware motor numbers — J1 → M3, J2 → M4, J3 → M1, J4 → M2.


Firmware

Architecture

ModuleRole
src/main.cppEntry point, FreeRTOS tasks, safety, telemetry
include/AppConfig.hWiFi SSID / password and UDP ports
lib/IMULSM6DSOX driver, calibration, Kalman filter, tilt emergency
lib/PIDGeneric PID
lib/controlCascaded angle → rate loop, X-frame motor mixing, yaw
lib/motorLEDC PWM outputs for the ESCs
lib/wifiWiFi access point + UDP transport
lib/commText command parser

Control loop

Roll and pitch use a cascaded controller: an outer attitude loop (angle) feeds a setpoint to an inner rate loop (angular velocity).

text
 ATTITUDE LOOP (outer, 200 Hz)        RATE LOOP (inner, 1 kHz)
 <--------------------------------> <------------------------------------------------------------------>

 stick setpoint (deg)          rate setpoint (deg/s)                         throttle x 2.5
                                                                                   |
        +             +-----+            +           +-----+        +-----+     +  v          +--------+
 ------->( X )------->|  K  |------------>( X )----->| PID |------->| MIX |----->( + )------->| Motors |
                      +-----+                        +-----+        +-----+                   +--------+
           ^ -                              ^ -
           |                                |
           | angle (deg)                    | rate (deg/s)
      +----------+                     +----------+
      |  Kalman  |                     |   Gyro   |
      +----------+                     +----------+
      (accel + gyro)
SignalCode
Angle error (°) = stick / 20 − Kalman angleFlightController::error_angle()
Rate setpoint (°/s) = K × angle error, K = ANGLE_TO_VELOCITY = 5 (P only)angle_to_velocity()
PID output per axis (telemetry CR, CP, CY)correction_vel() → pid_rate_roll/pitch/yaw()
Per-motor duty (0–255) = mix of PID outputs + throttle × 2.5mix(), then vTaskRateLoop in main.cpp
  • Attitude loop (vTaskAttitudeLoop, 200 Hz, priority 1): reads the Kalman-fused angles, compares them to the stick setpoint and turns the angle error into a rotation-rate setpoint. It is a pure proportional gain: it only decides how fast the drone should rotate to reach the desired angle.
  • Rate loop (vTaskRateLoop, 1 kHz, priority 2): reads the gyro, compares the measured rate to the setpoint and runs the PID whose gains are tuned live from the gamepad tool (pid kp ki kd). The D term is computed on the gyro measurement (not on the error), low-pass filtered, so a stick move does not kick the output. The correction is mixed onto the four motors (X frame), then the throttle is added.
  • Yaw skips the attitude loop: with no magnetometer the heading drifts, so the yaw stick is directly a rate setpoint (±400 → ±180 °/s), regulated by a PI (pidyaw kp ki) against the Z gyro. Centred stick = hold 0 °/s.
  • loop(): receives commands, handles the stop/resume latch, sends telemetry at 20 Hz.

Safety

Throttle at 0 cuts the motors and resets the PIDs; tilt beyond 60° cuts the motors until the drone is back under 30°; a stop command latches the motors off until resume; a 30 s watchdog reboots the board if loop() hangs.

Configuration

Edit firmware/include/AppConfig.h before building:

cpp
const char* ssid = "peter_pan";          // access point created by the ESP32
const char* password = "pierre qui vole";
uint16_t localPort = 8889;               // commands  (PC -> drone)
uint16_t hostPort  = 8894;               // telemetry (drone -> PC)

If you change the ports, update CMD_PORT / TELEMETRY_PORT in the Python tools as well.

Build and flash

Requirements: PlatformIO — either the VS Code extension or the CLI (pip install platformio). Dependencies (Arduino-ESP32, Adafruit LSM6DS, …) are downloaded automatically on the first build.

bash
cd firmware

# Build
pio run

# Flash (plug the ESP32 over USB)
pio run -t upload

# Serial monitor, 115200 baud
pio device monitor

If several serial ports are present, pick one explicitly:

bash
pio device list
pio run -t upload --upload-port /dev/cu.usbserial-XXXX

If the upload does not start ("Connecting....."), hold the BOOT button on the ESP32 until writing begins. Upload speed is set to 921600 baud in platformio.ini; lower upload_speed if the transfer is unreliable.

In VS Code, the same actions are available from the PlatformIO toolbar (✓ Build, → Upload, 🔌 Monitor).

At boot the drone must lie flat and still: the IMU is calibrated in setup() and the ESCs are held at idle for 3 s so they can arm.

UDP protocol

Commands are plain text, sent to 192.168.4.1:8889:

CommandEffect
commandPing, the drone answers ok on port 8894
rc <left> <forward> <up> <yaw>Pilot command. left/forward: ±400 (÷20 → ±20° setpoint); up: throttle 0–100 (× 2.5 → duty); yaw: ±400 (→ ±180 °/s)
pid <kp> <ki> <kd>Roll / pitch rate PID gains
pidyaw <kp> <ki>Yaw PI gains
stopEmergency stop, latched
resumeClears the emergency stop

Telemetry is broadcast at 20 Hz on 192.168.4.255:8894:

text
ROLL: 1.23 deg, PITCH: -4.56 deg | RA:1.10 PA:-4.30 | CR:2.10 CP:-3.40 | M1:5 M2:-1 M3:-5 M4:1 | GZ:-8.20 CY:3.10 | HZ:1000
FieldMeaning
ROLL/PITCHKalman-fused angles (°)
RA/PARaw accelerometer angles, before filtering (°)
CR/CPRoll / pitch PID outputs
M1..M4PID contribution per motor, throttle excluded
GZMeasured yaw rate (°/s)
CYYaw PI output
HZActual rate loop frequency

Debug messages (radio.my_printf(...)) are broadcast separately on port 8895.


Python tools

Setup

Python 3.10+ is required.

bash
cd python_tool
python3 -m venv venv
./venv/bin/pip install -r requirements.txt

Dependencies: pygame-ce (gamepad), PyQt5 + pyqtgraph (GUI and plots), numpy, colorama.

Before running any tool, connect the PC to the peter_pan WiFi network created by the ESP32. The drone is always at 192.168.4.1.

FileRole
gamepad_pilot.pyFlight GUI: gamepad control, live PID tuning, plots, CSV logs
udp_link.pyTelemetry / debug UDP receivers and telemetry line parser
esc_calibration.pyGuided ESC throttle-range calibration

Gamepad pilot

bash
cd python_tool
./venv/bin/python gamepad_pilot.py

Plug a PS4 DualShock 4 controller over USB (before or after launch — use "Rechercher la manette" to rescan). The tool sends rc commands at 50 Hz and refreshes the GUI at ~30 Hz.

Controls
InputAction
Left stick, verticalThrottle
Left stick, horizontalYaw
Right stickRoll / pitch (push forward = nose down, fly forward)
△ TriangleArm — throttle stays at 0 until armed
○ CircleDisarm (tool side), immediately sends rc 0 0 0 0
✕ CrossEmergency stop: sends stop, firmware cuts the motors and latches
□ SquareResume: sends resume, then re-arm with △ to get throttle back
L1 (held)Fine throttle mode: throttle change rate divided by 5
D-pad ← / →Yaw Kp − / + (step 0.02)
D-pad ↓ / ↑Yaw Ki − / + (step 0.01)

Unplugging the gamepad while armed disarms automatically and keeps sending zero throttle. stop / resume are repeated 5 times since UDP is unreliable.

Throttle modes
  • Incremental (default, "Gaz incrementaux") – the stick changes the throttle rate; releasing it (it springs back to centre) holds the current throttle. Well suited to hovering.
  • Direct – stick position = throttle; releasing the stick cuts throttle.
  • Slider ("Gaz au slider") – throttle set with the mouse, gamepad not required. Useful for bench tests.

The throttle curve exponent (1.0 = linear, 2.5 default, up to 4.0) and the incremental rate can be adjusted in the GUI to get finer control around hover.

GUI panels
  • Vol – arm / disarm / stop / resume buttons and throttle settings.
  • Manette – raw axis, button and hat values, to check the mapping.
  • Gains PID – Kp / Ki / Kd sliders for roll/pitch, sent live (pid), no reflash needed.
  • Gains lacet – yaw Kp / Ki, sent live (pidyaw).
  • Mesures – latest telemetry values, including loop frequency.
  • Journal d'essai (CSV) – start/stop logging, or log automatically while armed.
  • Right side – real-time plots of angles and per-motor PID corrections, plus a console showing firmware debug messages (port 8895).
Flight logs

Logs are written to python_tool/logs/vol-<timestamp>.csv, one row per telemetry frame (~20 Hz): IMU angles, setpoints and errors, PID gains in use, corrections and arming state. Header lines start with #:

python
import pandas as pd
df = pd.read_csv("logs/vol-....csv", comment="#")
Gamepad mapping

Axis and button indices depend on the OS / driver. If an axis is swapped or inverted, check the raw values in the Manette panel and edit the constants at the top of gamepad_pilot.py:

python
AX_YAW, AX_THROTTLE, AX_ROLL, AX_PITCH = 0, 1, 2, 3
BTN_STOP, BTN_ARM, BTN_DISARM, BTN_RESUME = 0, 3, 1, 2   # Cross / Triangle / Circle / Square
BTN_FINE = 4                                             # L1

STICK_TO_ANGLE and THROTTLE_GAIN are copied from the firmware for logging; keep them in sync if you change flight_controller.h.

ESC calibration

Teaches the four ESCs the 1000–2000 µs throttle range so the motors start together.

bash
cd python_tool
./venv/bin/python esc_calibration.py            # guided procedure
./venv/bin/python esc_calibration.py --dry-run  # rehearsal, sends nothing

Options: --ip (default 192.168.4.1), --max / --min (percent, default 100 / 0).

The script walks you through each step and waits for confirmation:

  1. Remove the propellers.
  2. Disconnect the ESC power.
  3. Power the ESP32 alone and connect to its WiFi.
  4. The tool sends 100 % continuously.
  5. Plug the ESC power back in — they beep (max recorded).
  6. The tool sends 0 % — confirmation beeps (min recorded).

Ctrl-C at any time brings the motors back to 0 % before exiting.

⚠️ This tool relies on an esc <percent> command that is not yet implemented in firmware/lib/comm/command_parser.cpp. It must be added to the firmware before the calibration can work.


Safety

  • Always remove the propellers for bench tests and ESC calibration.
  • Keep a finger on ✕ (emergency stop) during every flight test.
  • When tuning PIDs, start from low gains and increase gradually. When the IMU is remounted, check the yaw sign first (see YAW_DIR) at yaw Kp = 0.05.

Parts

24
QtyValueFootprintReferences
8MountingHole_PadMountingHole:MountingHole_2.5mm_PadH1, H2, H3, H4, H5, H6, H7, H8
310kResistor_SMD:R_0603_1608MetricR1, R2, R3
2100nCapacitor_SMD:C_0603_1608MetricC2, C3
2Conn_01x15_PinConnector_PinHeader_2.54mm:PinHeader_1x15_P2.54mm_VerticalJ6, J7
110uCapacitor_SMD:C_0603_1608MetricC4
110uCapacitor_SMD:C_0805_2012MetricC1
1AlimConnector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_VerticalJ5
1LSM6DSOTRimu:LSM6DSOTRU2
1Motor1Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ1
1Motor2Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ2
1Motor3Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ3
1Motor4Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ4
1R-78E3.3-0.5reg:CONV_R-78E3.3-0.5PS1

Similar boards

  • 2 layers127 × 114.3 mmNes, the printed circuit board in 3D

    Nes

    dkonigsberg/nestronic

    Nestronic Game Music Synthesizer Alarm Clock

    144 parts38
  • 2 layers163 × 72 mmOM-64DO, the printed circuit board in 3D

    OM-64DO

    OpenModbus/OM-64DO

    A compact industrial-grade 64-channel Modbus RTU output module.

    231 parts21GPL-3.0
  • 2 layersHB LC Dim6PWM CV, the printed circuit board in 3D

    HB LC Dim6PWM CV

    stan23/myPCBs

    Verschiedene Platinen für HomeMatic, AskSinPP und SmartHome

    57 parts21
  • 2 layers88.9 × 106 mmMarbles v70, the printed circuit board in 3D

    Marbles v70

    mort13/clandestine_circuitry

    Collection of diy synth projects

    208 parts12GPL-3.0
  • 4 layers154.9 × 128.4 mmDaisy hardware v1, the printed circuit board in 3D

    Daisy hardware v1

    rafkhan/lowstepper

    Dual phase manipulation low frequency oscillator by Okay Synthesizer.

    161 parts9
  • 4 layers49.8 × 106.5 mmWaves, the printed circuit board in 3D

    Waves

    marangisto/Waves

    Cordic Accelerated Voltage Controlled Oscillator

    154 parts4MIT
  • 4 layers70 × 60 mmTanklevel, the printed circuit board in 3D

    Tanklevel

    Th3Link/tanklevel

    This project provides a solution for measuring the liquid level in tanks, such as rainwater tanks, using the TL-136 pressure sensor.

    80 parts4CERN-OHL-S-2.0
  • 2 layers100 × 72 mmOM-16LED, the printed circuit board in 3D

    OM-16LED

    OpenModbus/OM-16LED

    A compact industrial-grade 16-channel Modbus RTU LED driver.

    100 parts3GPL-3.0

Questions

How big is the Peter pan PCB?

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

What parts does the Peter pan use?

24 parts, built around the R-78E3.3-0.5, ERJ3GEYJ103V, VJ0603V104ZXAPW1BC and M20-7821546. 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 Peter pan KiCad files?

From the pierre-bouckson/peter_pan repository on GitHub, at the commit this page was made from: the board is PCB/PCB.kicad_pcb and its schematic PCB/PCB.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Peter pan design in my own project?

Its repository states no licence, so its author keeps all rights: ask pierre-bouckson before reusing the design.