Episode 1: I’m Writing My Own Flight Controller from Scratch — Here’s What Happened After 3 Weeks

Ivan T.Ivan T.
7 min read

I’m Ivan T., a senior EE student from the Philippines. I’ve never written a flight controller before, not even touched Ardupilot or Betaflight. But some weeks ago, I decided to make my own from scratch using cheap parts, raw code, and way too much curiosity.

This post covers my journey from Day 0 to Day 22, detailing what I’ve learned, what broke, and where I’m headed.

Progress Snapshot (Days 0–22)

DayHighlight
1Ordered MPU6050 & STM32F411, started reading basic aerospace for drones and other related books
2Made initial drone schematic, planned for LoRa + GPS telemetry
3Decided to use SX1278 (budget), researched radio latency tradeoffs
4Discovered quaternions, watched 3blue1brown videos, & tried hand calculation for better understanding
5Explored BMP280 barometer + altitude calculation with I2C
6Soldered IMU & STM32, reading books again
7Setup STM32 on Arduino IDE, explored PlatformIO, modular code
8Successfully ran STM32 + FreeRTOS + PlatformIO, built custom headers
9Learned MPU6050 registers, applied complementary filter (no mag yet)
10Wrote BMP280 + MPU6050 reusable libraries
11Ordered OLED, LoRa, buck converters, no major coding progress
12Understood and simulated quaternions in VPython
13Real-time VPython visualizer working
14Began porting sensor code to STM32, faced I2C voltage mismatch
15Rewrote libraries, received more modules, OLED glitchy at first
16Got OLED working, started reading magnetometer datasheet
17Discovered clone QMC5883, wrote raw I2C interface after struggle
18Burned 2 buck converters, read “Show Your Work” during brownout
19Calibrated compass, adjusted IMU & magnetometer to NED orientation
20Wrote full custom Madgwick library, solved FreeRTOS dt timing issues
21Installed LoRaLib, discovered Git, made first code snapshot
22Tried SX1278 TX/RX across ESP32 + STM32

Note: I officially started this project on June 2, 2025, but not every day has progress. The “Day” count below refers to the days I actually worked, not calendar days. Some days I was burned out, busy, or just didn’t get anywhere, so they’re not included here. I am writing this now on Day 23 (June 26).

Phase 1: Getting Started (Days 0–5)

I didn’t plan to write my own flight controller.

Originally, I just wanted to build a drone. But the more I read, the more I realized I didn’t want to just assemble something, I wanted to understand it. From orientation math to sensor fusion to stabilization. All of it.

So I started with what I had: no real drone background, no flight control experience, and definitely no fancy hardware. Just curiosity, my laptop, and some cheap modules I could afford.

I read about UAVs, MPU6050, quaternions, I2C communication, and barometers. I decided to order a cheap drone frame (f450) online for 800 (around $14 USD) because it fits well with my general drone plans. On Day 4, I discovered quaternions and got engrossed in a 3Blue1Brown video series. That's when everything really made sense. The challenge wasn't just coding, it was building a system that understands rotational math.

At this point, I decided to use the STM32F411CE "Blackpill" (which I had never used before) as the main processor. For telemetry, I went with SX1278 LoRa since it’s cheap and enough for my range. I also planned to eventually integrate GPS and compass, but at this phase, it was just me, a bunch of YouTube tabs, Books, and some shaky notes.

I didn’t know what I was doing, but I was in too deep to stop.

Phase 2: Coding Foundations (Days 6–14)

This is where things started feeling real.

My drone frame (f450) & IMU came and I finally soldered the IMU to my STM32 and booted it using the Arduino core, but I knew that wouldn’t scale and not a good platform for long term use. So I switched to PlatformIO and set up FreeRTOS, which I’d never used before. Took me hours to figure out build flags, memory optimization, and how to flash properly, but it worked.

From there, I began treating the project like a real embedded system (though I'm no expert):

  • I created modular headers for the MPU6050 and BMP280

  • Reading datasheets & exploring register-level I2C

  • Started testing complementary filters with only accel + gyro at first

  • Still no magnetometer, just trying to get the angles to look stable

Then came quaternion simulation. I used VPython to visualize the outputs and compare rotations. That gave me an actual feel for what the orientation data was doing. It helped me catch early bugs like signs flipping or axis mismatch.

Even though this phase was mostly in the IDE and simulation tools, it was the foundation for everything else. I wasn’t flying, but I was finally moving.

Phase 3: Hardware + Problems (Days 15–18)

If Phase 2 was all code, Phase 3 was a war with hardware.

I started connecting more modules, OLED, compass, buck converters, and everything started messing up. Literally. My first OLED wouldn’t display properly and i switched library from U8G2 to an Adafruit library and it works. Then two buck converters fried (shorted because of soldering), a dumb mistake.

To make matters worse, I discovered that my magnetometer wasn't an HMC5883L as I had thought, it was a QMC5883 clone. This meant no library support, as I tried three libraries and none worked. So, I had to write my own raw I2C interface for it, figuring out which registers were valid through trial and error. The I2C address was unusual because even the QMC5883L (an HMC clone) has a different I2C address than mine. But after extensive Googling, I found out it was a QMC5883P. I located the datasheet and began writing the interface.

It was frustrating as hell. Debugging I2C without a logic analyzer felt like reality just slapped me in the face for being broke, haha.

Because my hometown experiences frequent brownouts (it’s nothing new), I had to stop coding one night, my laptop battery was low, and I couldn’t charge it. So I just paused everything and started reading Show Your Work by Austin Kleon.

That book hit me. It made me realize that it’s okay to share my journey, even if it’s flawed, incomplete, or messy. That’s actually the point. And that’s why I’m writing this now, not to teach, but to show the process. Even if I fail, I think it’s worth sharing.

So I decided I’d start logging this whole process properly. Not just for others, but for future me.

Phase 4: Fusion + LoRa (Days 19–22)

This is where things started to feel like a real flight controller.

I finally calibrated the compass correctly and aligned all my sensor axes in the NED (North-East-Down) orientation. For the first time, my IMU and magnetometer data made directional sense, so I no longer had to guess if I was facing north or just imagining it. That said, compass calibration was a real pain. It took trial and error, and I’m still not 100% confident it’s perfect.

Then, on Day 20, I wrote my own Madgwick filter, no library. I handled the quaternion math myself, managed FreeRTOS ‘dt’ timing, and got stable orientation output. That alone felt like a milestone. Months ago, I didn’t even know what a quaternion was.

Discovering Git was transformative for my project. Initially, I found it intimidating, but it turned out to be quite straightforward and invaluable for solo work.

After I that, I set up LoRa communication between my STM32 and ESP32. I tested SX1278 modules using LoRaLib and got basic TX/RX working across boards. While I wait for my nRF24L01 + PA/LNA modules to arrive, I’ve decided to take a short break. Things are getting busy on my end with other responsibilities, and I think I need to take a quick break to rest and refocus before diving into the next part of this project.

Final Thoughts

My progress might seem slow compared to others, but this project is being built under serious limitations, not just technical, but financial.

Even the basic parts I still need, motors, ESCs, LiPo battery, charger, are beyond my current budget. I don’t even plan to add a camera for now because it’s just not practical. A complete drone build can get expensive fast, and I’m working with what I have.

My entire flight controller setup, the STM32, sensors, etc., only cost me around ₱400 (roughly $7 USD), not including GPS. If I bought an off-the-shelf flight controller like Betaflight or Pixhawk, I’d easily blow my entire budget before I could even start coding.

That’s why I’m doing this the hard way, writing everything from scratch, learning step by step, and making every peso count. It’s slow, but it’s mine.

This is only the beginning. More logs coming soon.

0
Subscribe to my newsletter

Read articles from Ivan T. directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ivan T.
Ivan T.

just a senior EE student trying to build a drone from scratch