An STM32 HAL example of arming and sending a reference speed to an ESC (electronic speed controller) that supports DShot (Digital Shot) protocol.
Quadcopters are inherently unstable. They only become stable due to control. That makes them excellent plants1 to elevate your control system design skills. There are many ways to start your journey with drones. You can buy a complete device that is ready to use out of the box, with all the necessary firmware preinstalled. This is for people who need it fly now and want to focus on gaining flying experience2. Some of us take the hard way and build their first drone from scratch including all the software needed to stabilize it and control it remotely. A hardcore DIYer would probably consider developing even his or her own ESCs. Here we take a bit less exteme approach and use a commercial ESC. Oh, and in this example we address only arming, setting a spin direction, and sending a reference speed to the ESC. You can consider it being the very first step in developing your own drone.
Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32L4xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.
If you are new to the DShot protocol and BLHeli_S/BLHeli_323 firmware
- DSHOT - the missing Handbook (Brushless Whoop)
- DShot ESC's for Meltybrains (Spencer's Hardware Blog)
- DSHOT on Mbed
- ESC protocols explained for beginners (PWM, OneShot, DSHOT, calibrating!)
- BLHeli_32 Is Finished? - Time To Back AM32! (Mads Tech)
- The End of BLHeli_32 and The Future of ESC Firmware in FPV Drones (Oscar Liang)
- BLHeli_32 ESC - The Facts Today & Questions Answered
- BLHeliSuite and BLHeliSuite32
- Dshotprog spec BLHeli_S
- The Betaflight Open Source Flight Controller Firmware Project
- DShot commands
- ESC Little-Bee Mini 30A BLHeli_S 2-6S
- Skystars Talon32 40A BLHeli_32 3-6S
- V2306 V3.0 VELOX 2550KV (T-MOTOR)
- HQProp S3 (Ethix)
- 2200mAh 11.1V 30C 3S1P LiPo battery4
Warning
Propellers that spin at tens of thousands rpm are not toys ❗
Warning
LiPo batteries are not toys either - learn to handle them before you use one in your project ❗
The PWM pin operates in the push-pull mode. However, if the ESC is powered before the uC, it is advisable to have a pull-down resistor (e.g. 4k7 to draw below 1 mA from the GPIO), to get consistent behaviour at the startup phase (the DShot line idles low). It's a good practice not to have signal lines flapping in the breeze. Exactly the same pin is used to configure the ESC over UART (19200). Remove the resistor for the UART communication.
- stm32_hal_dshot (MIT license)
- DShotRMT (ESP32, Arduino framework, MIT license)
- Oscar Liang - FPV Drone Tutorials and Reviews
Get familiar with attitude and heading reference systems (AHRS):
- Attitude and heading reference system (Wikipedia)
- The Difference Between IMU, AHRS, and INS (Inertial Sense, Inc.)
Play with a selected one. Some examples are:
- BNO055 (Bosch Sensortec GmbH)
- BNO085/BNO086 (Ceva, Inc.)
There are eval boards ready for breadboarding from e.g. Adafruit Industries.
Then build a test rig to safely evaluate your control algorithms. Check some common approaches on YT:
- Aluminum PID test and tuning rig stand for quadcopter UAV drone
- A 4DOF Quadcopter Test Bench
- Drone Gimbal Rig 2
- Drone Jig
- UAV Test Stand in Action
- Normal Quadrotor in a Gyroscopic Test Bench Experiment - Grin UFJF
- The FFT GYRO, the best tool for drones.
Search for more: drone/quadcopter test bench/platform/jig/rig/stand.
Create your own home laboratory/workshop/garage! Get inspired by ControllersTech, DroneBot Workshop, Andreas Spiess, GreatScott!, ElectroBOOM, Phil's Lab, atomic14, That Project, Paul McWhorter, and many other professional hobbyists sharing their awesome projects and tutorials! Shout-out/kudos to all of them!
Warning
Electric drives - do try them at home ❗
190+ challenges to start from: Control Engineering for Hobbyists at the Warsaw University of Technology.
Stay tuned ❗
Footnotes
-
Check the regulations before you do that - in most countries you have to undergo some basic training and get an official certificate to be allowed to fly a drone. ↩
-
BLHeli comes from brushless helicopter. _S denotes an 8-bit version developed by Silabs. _32 indicates a 32-bit version. ↩
-
Why not a bench power supply? If you already have one capable of delivering 30 A, lucky you 🙂 If not, it is usually much cheaper to buy a battery. It's roughly 25 EUR vs. 250 EUR. You can charge the battery from any CC/CV power supply if you know what you are doing. If you are not sure, use a quality charger. I'm quite happy with iMAX B6 Mini from SKYRC (approx. 35 EUR). ↩