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. Nevertheless, it can be fairly complicated to arrange and calibrate appropriately. If a magnetometer is misconfigured or poorly calibrated, it will possibly really 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 answerable for any harm ensuing from following these directions. Please seek advice from Betaflight’s official documentation for particulars: https://www.betaflight.com/docs/wiki/guides/present/magnetometer
Try my tutorials on:
What Is a Magnetometer (and Why It Issues)
The magnetometer tells the flight controller which path the quad is going through. This info helps the drone to:
- Keep heading in Place Maintain mode
- Enhance GPS Rescue mode accuracy
- Cut 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 Value Having: GOKU GM10 Nano V3 (With Compass)
How you can Join Magnetometer to Flight Controller
In case your GPS module features a compass, it ought to have two extra 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 maintain the compass as far-off as doable 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 more durable to get clear compass readings just because all the pieces 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, test energy and wiring.
Determine Magnetometer Chip
Open the CLI and kind:
standing
This confirms whether or not the magnetometer is detected and in addition helps establish 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. Nevertheless, 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 exhibiting 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, it’s possible you’ll want to regulate the magnetometer alignment in Betaflight settings.
Why Alignment Is Typically Wanted
Should you mount the magnetometer completely parallel to the flight controller, setup could be easy. Nevertheless, on most GPS modules the magnetometer is positioned on the alternative aspect of the GPS antenna. And because the 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, maintain issues easy:
- Mount the GPS flat and degree 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, degree with the body and FC (utilizing double-sided tape and zip tie).
As a result of the compass is solely flipped over on the pitch axis, I chosen “CW 0° Flip” beneath Magnetometer Alignment in Betaflight.
Right here’s a helpful cheat sheet you need to use for widespread 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 newcomers, which is why I strongly advocate mounting the GPS flat if doable so that you don’t should cope with this 🙂
That mentioned, the Alignment Device in iNav Configurator is extraordinarily useful—even in the event you don’t use iNav.
How you can use it:
- Open iNav Configurator
- Enter Demo Mode (so you may join with out a FC)
- Go to Alignment Device
- 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 is just not the identical as true north, and Betaflight wants your native magnetic declination worth to right this distinction.
Declination varies by location. Yow will discover it utilizing a trusted web site reminiscent of: 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, you need to carry out compass calibration on the location the place you propose to fly. Keep nicely away from something that would trigger magnetic interference, reminiscent of:
- Metallic objects
- Vehicles
- Energy traces
- Strengthened concrete
You possibly can provoke calibration both by clicking the Calibrate Magnetometer button in Betaflight Configurator (setup tab), or by utilizing stick instructions. I personally choose stick instructions, because it permits me to unplug the USB cable and rotate the quad freely.
How you can Calibrate Magnetometer
- Take away propellers and energy up the quad
- Provoke calibration utilizing the stick command:
- Pitch down + yaw up-right → you need to hear 2 beeps
- Spin the quad rapidly to start out 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:
- Stable LED = calibration in progress
- Regular blinking = calibration accomplished
How you can Transfer the Quad Throughout Calibration
In the course of the 30-second calibration window:
- Maintain the quad by the battery
- Swing your arm in a figure-8 sample
- On the similar time, yaw the quad left and proper randomly
- Slowly flip your whole physique by taking small steps. By the top of the calibration, you need to have accomplished roughly a full 360° rotation.
Compass calibration often solely must be carried out as soon as inside your native space. Nevertheless, in the event you journey far-off from dwelling, it’s a good suggestion to recalibrate.
Validate Heading
After calibration, confirm the heading fastidiously:
- Use the Betaflight Configurator dwelling display screen or
- Allow the Compass Bar within the OSD
Examine the heading towards a smartphone compass app. Ensure that the app is ready to true heading, not magnetic heading.
Check by going through totally 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 fallacious:
- Recheck compass orientation
- Strive totally different Magazine Alignment choices in Configurator (CW0 / CW90 / CW180 / CW270)
- Redo calibration in a clear setting
- Re-test after each change
In some circumstances, the compass itself could also be defective. I examined 3 totally different GPS modules and located that one had a defective compass—so this isn’t unusual.
Remaining Ideas
You possibly can fly Betaflight with out a magnetometer—however if you’d like 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 alter {hardware} or GPS placement. And don’t overlook to recalibrate in the event you fly far-off out of your common location.
