Skip to content
Arthur Benemann edited this page Mar 15, 2013 · 1 revision

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/BR-HMC5843-01-2.jpg

Method One: Using a cable

A magnetometer is supported by some versions of APM code, such as !ArduCopter NG and !ArduCopter Mega. It is not supported by !ArduPilotMega 1.0 for airplanes, although it may be in future versions. (Fixed wing autopilots do not need magnetometers, since the GPS gives a directional vector when the aircraft is in motion. Rotary wing aircraft, which are often hovering in a stationary position where GPS cannot give a directional vector, do need magnetometers.)

You can attach the HMC5843 magnetometer to the APM IMU shield's I2C sensor port, which looks like a GPS connector but says "No GPS". One reason to do this is you intend to daisy-chain other I2C sensors to your board.

One way to do this is to modify a GPS cable, cutting off the connector on one side and soldering the wires to the right pads on the magnetometer board. You'll only be using four of the six wires; the other two can be cut off. Plug the connector into the shield and look at the bottom of the shield where you should see "SCL", "SDA", "+5V", "GND" written, corresponding to the four wires. These should be matched up to the same pins on the magnetometer, as shown below

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/magnetometercable.jpg

Here's a picture of how it should look (we recommend threading the cable through the hole before soldering for strain relief):

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/IMG_4888.JPG

Plug it in here:

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/IMG_4891.JPG

Ensure that the small solder blob jumper on the magnetometer is set to 5V before connecting it. If it isn't, you should switch it as shown below:

http://arducopter.googlecode.com/svn/images/Magneto/Mag_HMC5843_jumper.jpg

Method Two: Mounted on the board

If you don't plan on using the 4-pin I2C connector on the shield for anything else, you can mount the magnetometer directly on top. Again, check that the voltage solder jumper is in the 5V position, as discussed above.

You can use a 4 pin breakaway header as a standoff. Take care to align the magnetometer and shield edges. Precision here will reduce the amount of trimming you have to do later.

First, snap off the mounting area of the magnetometer:

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/BR-HMC5843-01-3.jpg

Now, solder in the four pin header (example of the header shown on the table next to the board). It's best to solder the header with the long pins down, going through the board.

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/IMG_4889.JPG

Finally, solder on the magnetometer component side down, as shown here:

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/IMG_4890.JPG

To enable the magnetometer in the APM code, use the CLI and in setup mode, enter "compass on", as shown here:

http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/Compasssetting.JPG

If just want to test your magnetometer quickly, you can load and run the APM_Compass_test in the Examples folder of the APM_Compass libraries of the APM code. Just load the sketch and view the data in the Serial Monitor of the Arduino IDE (38,400 baud).

Sample data looks like this (when moving the board around a bit):

Heading:23.04  (174,-74,4096)     offsets(-87.00,37.00,-2048.00)
Heading:22.82  (145,-61,4096)     offsets(-87.00,37.00,-2048.00)
Heading:9.62  (177,-30,4096)     offsets(-88.50,37.00,-2048.00)
Heading:7.50  (167,-22,4096)     offsets(-88.50,37.00,-2048.00)
Heading:31.54  (145,-89,4096)     offsets(-88.50,44.50,-2048.00)
Heading:28.94  (132,-73,4096)     offsets(-88.50,44.50,-2048.00)
Heading:15.85  (162,-46,4096)     offsets(-88.50,44.50,-2048.00)
Heading:22.88  (173,-73,4096)     offsets(-88.50,44.50,-2048.00)
Heading:-0.38  (152,1,4096)     offsets(-88.50,44.00,-2048.00)
Heading:15.84  (148,-42,4096)     offsets(-88.50,44.00,-2048.00)
Heading:10.28  (171,-31,4096)     offsets(-88.50,44.00,-2048.00)
Heading:24.47  (145,-66,4096)     offsets(-88.50,44.00,-2048.00)
Heading:40.25  (163,-138,4096)     offsets(-88.50,68.50,-2048.00)
Heading:34.28  (157,-107,4096)     offsets(-88.50,68.50,-2048.00)
Heading:26.72  (147,-74,4096)     offsets(-88.50,68.50,-2048.00)
Heading:51.87  (84,-107,4096)     offsets(-88.50,68.50,-2048.00)
Heading:49.44  (89,-104,4096)     offsets(-88.50,68.50,-2048.00)

Otherwise, you can test the sensor in the APM CLI, by selecting "compass" in the "test" menu.

Clone this wiki locally