A magnetometer (also called a compass) might be very helpful for GPS Rescue and Place Maintain in Betaflight, because it improves accuracy and total efficiency. Nonetheless, it can be fairly complicated to arrange and calibrate appropriately. If a magnetometer is misconfigured or poorly calibrated, it will possibly truly make issues worse—inflicting drifting, incorrect heading, and even flyaways.
On this information, I’ll stroll you thru magnetometer orientation, declination, calibration, and verification step-by-step to make the method simpler to know.
Disclaimer: This information displays how I personally arrange and calibrate a magnetometer. I’m not accountable for any harm ensuing from following these directions. Please discuss with Betaflight’s official documentation for particulars: https://www.betaflight.com/docs/wiki/guides/present/magnetometer
Take a look at my tutorials on:
What Is a Magnetometer (and Why It Issues)
The magnetometer tells the flight controller which path the quad is dealing with. This info helps the drone to:
- Keep heading in Place Maintain mode
- Enhance GPS Rescue mode accuracy
- Scale back yaw drift throughout GPS-assisted flight modes
Some GPS modules have a built-in magnetometer.
GPS Suggestions
See my GPS testing right here: https://oscarliang.com/gps-review/
Prime Performer: GEPRC M1025Q (With Compass)
Prime Performer: HGLRC M100 5883 (With Compass)
Smallest Price Having: GOKU GM10 Nano V3 (With Compass)
Methods to Join Magnetometer to Flight Controller
In case your GPS module features a compass, it ought to have two further pads: SCL and SDA. These are for the I2C bus utilized by the magnetometer.
Wiring is straightforward:
- SDA (GPS) → SDA (FC)
- SCL (GPS) → SCL (FC)
The place to Mount Magnetometer
You need to hold the compass as far-off as potential from sources of electromagnetic interference, together with:
- ESC
- Motors
- Motor wires
- Energy cables (e.g. XT60)
- Motion cameras
Good places for mounting a GPS module embrace:
- Above the FPV digital camera
- On the rear of the drone (so long as it’s not too near the VTX antennas)
- On the battery strap
For small quadcopters (e.g. beneath 5-inch), it’s tougher to get clear compass readings just because the whole lot is packed so carefully collectively.
Betaflight Setup
In Betaflight Configurator:
- Go to Configuration → System Configuration
- Allow Magnetometer
- Save and reboot
After rebooting, the magnetometer icon (Magazine) on the prime of the configurator ought to gentle up. If it doesn’t, examine energy and wiring.
Establish Magnetometer Chip
Open the CLI and kind:
standing
This confirms whether or not the magnetometer is detected and likewise helps determine the chip. Widespread magnetometer chips utilized in GPS modules embrace HMC5883 and QMC5883.
Understanding Magnetometer Orientation
Identical to a gyro, a magnetometer has three axes: X, Y, and Z. Nonetheless, these axes are outlined by the orientation of the magnetometer chip itself, not the way it’s mounted within the drone.
In your GPS module, search for a small dot on the magnetometer chip—this marks pin 1.
Google the chip’s datasheet on-line. It ought to embrace a diagram displaying how the X, Y, and Z axes are oriented relative to the chip and the small dot. For the QMC5883 magnetometer I’m utilizing:
- X-axis factors down
- Y-axis factors proper
- Z-axis factors up
Betaflight expects the magnetometer to be oriented like this:
- X-axis → pointing ahead
- Y-axis → pointing left
- Z-axis → pointing up
Relying on the way you mount your GPS module, you could want to regulate the magnetometer alignment in Betaflight settings.
Why Alignment Is Usually Wanted
When you mount the magnetometer completely parallel to the flight controller, setup can be easy. Nonetheless, on most GPS modules the magnetometer is situated on the other facet of the GPS antenna. And for the reason that GPS antenna should face the sky, the magnetometer often finally ends up being the other way up, which suggests alignment modifications are often inevitable.
If that is your first time utilizing a compass, hold issues easy:
- Mount the GPS flat and stage relative to the body and FC
- Keep away from angled or tilted mounts
- Get it working first earlier than making an attempt customized alignment
In my setup, I stored issues easy by mounting the GPS on the entrance of the quad, stage with the body and FC (utilizing double-sided tape and zip tie).
As a result of the compass is just flipped over on the pitch axis, I chosen “CW 0° Flip” beneath Magnetometer Alignment in Betaflight.
Right here’s a useful cheat sheet you need to use for frequent compass alignments.
Customized Alignment (Superior)
If you’re utilizing a GPS mount with a tilt angle, then Customized Alignment is required. This may be complicated for inexperienced persons, which is why I strongly suggest mounting the GPS flat if potential so that you don’t must take care of this 🙂
That stated, the Alignment Instrument in iNav Configurator is extraordinarily useful—even should you don’t use iNav.
Methods to use it:
- Open iNav Configurator
- Enter Demo Mode (so you may join with no FC)
- Go to Alignment Instrument
- Choose X, Y, Z (extra dependable than selecting magnetometer)
- Alter the X, Y, Z sliders till they match your magnetometer’s bodily orientation
- Be aware of the ultimate Roll (X), Pitch (Y), and Yaw (Z) values
Now return to Betaflight:
- Within the Configuration tab, choose Customized beneath Magnetometer Alignment
- Enter the Roll, Pitch, and Yaw values
Alternatively, you are able to do this by way of the CLI:
set align_mag = customizedset mag_align_roll = Xset mag_align_pitch = Yset mag_align_yaw = Zsave
Set Magnetic Declination
Magnetic north will not be the identical as true north, and Betaflight wants your native magnetic declination worth to appropriate this distinction.
Declination varies by location. You could find it utilizing a trusted web site corresponding to: https://www.magnetic-declination.com/
Instance:
- For Los Angeles, USA, the magnetic declination is +11° 24′.
- Convert this to decimal (Google can do that for you): 11.4°
Enter this worth within the Configuration tab
Or enter it in CLI:
set mag_declination = 11.4save
Calibrate Magnetometer
Ideally, it is best to carry out compass calibration on the location the place you propose to fly. Keep nicely away from something that might trigger magnetic interference, corresponding to:
- Metallic objects
- Automobiles
- Energy traces
- Strengthened concrete
You’ll be able to provoke calibration both by clicking the Calibrate Magnetometer button in Betaflight Configurator (setup tab), or by utilizing stick instructions. I personally want stick instructions, because it permits me to unplug the USB cable and rotate the quad freely.
Methods to Calibrate Magnetometer
- Take away propellers and energy up the quad
- Provoke calibration utilizing the stick command:
- Pitch down + yaw up-right → it is best to hear 2 beeps
- Spin the quad shortly to begin calibration
- You’ll hear 7 quick beeps indicating calibration has begun
- You now have 30 seconds to finish calibration
- The quad will make 3 beeps when calibration is full
In case your quad doesn’t have a beeper, you may have a look at the FC LED as an alternative:
- Strong LED = calibration in progress
- Regular blinking = calibration accomplished
Methods to Transfer the Quad Throughout Calibration
Through the 30-second calibration window:
- Maintain the quad by the battery
- Swing your arm in a figure-8 sample
- On the identical time, yaw the quad left and proper randomly
- Slowly flip your complete physique by taking small steps. By the top of the calibration, it is best to have accomplished roughly a full 360° rotation.
Compass calibration often solely must be achieved as soon as inside your native space. Nonetheless, should you journey far-off from residence, it’s a good suggestion to recalibrate.
Validate Heading
After calibration, confirm the heading rigorously:
- Use the Betaflight Configurator residence display screen or
- Allow the Compass Bar within the OSD
Evaluate the heading towards a smartphone compass app. Ensure the app is about to true heading, not magnetic heading.
Check by dealing with completely different instructions:
- Face north → ought to learn north
- Rotate east, south, and west → confirm accuracy
If the Heading Is Incorrect
If the heading is clearly incorrect:
- Recheck compass orientation
- Strive completely different Magazine Alignment choices in Configurator (CW0 / CW90 / CW180 / CW270)
- Redo calibration in a clear surroundings
- Re-test after each change
In some circumstances, the compass itself could also be defective. I examined 3 completely different GPS modules and located that one had a defective compass—so this isn’t unusual.
Last Ideas
You’ll be able to fly Betaflight with no magnetometer—however in order for you dependable Place Maintain and correct GPS Rescue, a correctly configured and calibrated magnetometer could make a distinction. As soon as it’s arrange appropriately, you hardly ever want to the touch it once more except you modify {hardware} or GPS placement. And don’t overlook to recalibrate should you fly far-off out of your common location.
