In my last post I’ve showed how to disable internal MHC5883L compass on Flip32+ (10DOF) flight controller board. Now it’s time to fix what we’ve broken last time, and connect external MHC5883L compass with I2C bus.
In my case I used very popular setup: u-blox NEO-6M GPS module with integrated MHC5883L compass. So you have both GPS and magnetometer in one case. Pretty nice. I’ve described how to connect NEO-6M GPS few weeks ago, so that part should be covered. The only new thing is compass itself. And hardware setup for it is very simple. In addition to GND and +5V lines you only have to connect SDA and SCL lines to bottom line of connectors right to USB port on Flip32. SDA to SDA, SCL to SCL. In case of I2C we do not have swap lines or do any other kinds of voodoo.
And that is all. Simple, right? After booting the board MAG sensor should be enabled and compass should be working.
The only thing that is left is calibration and some additional magic. Let’s begin with magic. Circuit orientation on external board can be different than internal’s. And Cleanflight will have absolutely no idea about that if we will not tell it about that. In case of Flip32, X axis of HMC5883L covers with it’s roll axis. Compass inside my GPS module is not only rotated by 90 degrees, but also flipped upside-down. So, not only north was pointing east. East was pointing west as well. Rotated and mirrored at the same time. Luckily, MultiWii, Baseflight and Cleanflight developers thought about that and the is CLI command that fixes it: align_mag. It can take following values:
|1||CW0_DEG||not rotated or flipped|
|2||CW90_DEG||rotated by 90 degrees (Z axis), not flipped (X axis)|
|3||CW180_DEG||rotated by 180 degrees (Z axis), not flipped (X axis)|
|4||CW270_DEG||rotated by 270 degrees (Z axis), not flipped (X axis)|
|5||CW0_DEG_FLIP||rotated by 0 degrees (Z axis), flipped (X axis)|
|6||CW90_DEG_FLIP||rotated by 90 degrees (Z axis), flipped (X axis)|
|7||CW180_DEG_FLIP||rotated by 180 degrees (Z axis), flipped (X axis)|
|8||CW270_DEG_FLIP||rotated by 270 degrees (Z axis), flipped (X axis)|
In case of Flip32’s original compass it was case 1. No rotation and not flipped. In case of this NEO-6M it was case 8. So, typing in CLI following fixed misalignment.
Then standard MAG calibration and done. New compass connected and configured. Hopefully far enough for power cables that will not drift any more.
External HMC5883L will work only in internal, built-in, circuit has been physically disabled. I2C bus does not allow for two devices with the same address to work together! So, either internal, or either external. The is no software solution to disable internal magnetometer! Circuit has to be either removed or SDA line has to be cut. I prefer complete removal.