Analyze Drone Flight Logs with Python on a Pi
Read ArduPilot .bin logs, plot altitude, battery and vibration, and find out why a flight went wrong.
Every ArduPilot flight records hundreds of values per second. pymavlink can read those logs, and matplotlib turns them into charts that reveal vibration, voltage sag and tuning problems.
Mission steps
Download the log
Copy the .bin file from the flight controller's SD card or download it with Mission Planner or QGroundControl.
Install tools
pip install pymavlink matplotlib in a virtual environment.
Read messages
The script extracts barometer altitude and battery voltage over time.
Plot and compare
Look for voltage drops on punch-outs and altitude wobble that signals tuning or vibration issues.
Check vibration
Plot VIBE messages; values consistently above about 30 m/s² usually mean you need better motor or FC soft-mounting.
Code
from pymavlink import mavutil
import matplotlib.pyplot as plt
log = mavutil.mavlink_connection('flight.bin')
t, alt, tv, volt = [], [], [], []
while True:
m = log.recv_match(type=['BARO', 'BAT'])
if m is None: break
if m.get_type() == 'BARO': t.append(m.TimeUS / 1e6); alt.append(m.Alt)
else: tv.append(m.TimeUS / 1e6); volt.append(m.Volt)
fig, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(t, alt); ax[0].set_ylabel('Altitude m')
ax[1].plot(tv, volt, color='orange'); ax[1].set_ylabel('Battery V')
plt.savefig('flight.png')Tip: test every script on the bench before installing it in a moving machine.
Questions
Betaflight logs too?
Betaflight uses a different format (blackbox). Use the free Blackbox Explorer or the orangebox Python library.