STM32-Based Drone
Key Tech: 3D Printing, C++, DC Motors, Fusion, I2C, JavaScript, KiCad, LTspice, SPI
Project Goal:
The goal of this project was to challenge myself in combining my mechanical design skills with my growing knowledge of microcontrollers and sensors and desire to master PID loops to create a drone from the ground up.
What It Does:
Uses accelerometer readings and a PID loop to self-stabilize, controlling the DC motors via PWM. Has an onboard ESP8266 to host a controller web page to command direction.
Development Process:
Research Phase
I challenged myself to re-use parts of an existing (under-performing) drone I owned and design around the DC motors and propellers it came with to recycle existing parts I had and set some parameters early on.
Soon figured out that the brushed DC motors I had were not ideal for a good torque/weight ratio but went ahead.
Sized MOSFETs, boost and buck converters, and core microcontroller to use based on a target 10 kHz control loop speed.
Microcontroller chosen was the STM32F411CEU6 (packaged as WeAct Black Pill V2.0).
Used LTspice to model responses of the MOSFETS to hit a target loop Hz of 10 kHz.
Profiled the motors I had by hooking them up to a bench power supply and measuring the gram force thrust produced using a scale.
Maybe not the most accurate but it's the best I could do for these motors bring up very little info when searching for their part numbers.
Limited by my power supply, I had to extrapolate to find the maximum current draw for a gram force that would provide enough lift for my estimated weight.
Sized and purchased a battery to last 7 minutes.
Motor Thrust Profiling
Current Draw Estimation
LTspice MOSFET response simulation
Design Phase
From here I looked into popular drone frame shapes. Looking at other similarly sized drones on the market, the majority were X-patterned with motors equally spaced apart but one that caught my eye was the DJI Mavic Pro shape. Knowing DJI is known for their high-quality, highly stable drones, I wanted to copy this design, having the two front motors closer together, but I suspect this is due to the added extra weight of their camera at the front of the drone. As my centre of mass as quite centered, designing like this didn't quite make sense for me.
I then designed the enclosure for my motors and drone frame to all be modularly 3D printed due to the print bed constraints of the Ultimaker 2+ and BambuLab X1Cs at uOttawa.
Designed the schematic in KiCad and layout of electronics on a protoboard in Fusion.
Modelled Protoboard in Fusion
Protoboard & Electronics Schematic
Prototyping Phase
Started printing the frame and the motor enclosures and testing those fits. Had to adjust some tolerances and re-print.
Started understanding the pinouts, how to use HAL (hardware abstraction layer) to specify pin functions, and started writing the code for the STM32 to access the right pins to communicate with the ESP8266 and PWM.
Wrote the code for the ESP8266 server and tested the communications.
Motor Enclosure
3D-printed using BambuLab printers.
Frame Assembly
3D-printed using Ultimaker and Raise3D printers.
Webapp Controller
Hosted locally via ESP8266.
Testing Phase
Have yet to test... 😔 Still working on assembling it.