Calibrating the magnetometer :
- This time you can shake the board as much as you want, but move it away from magnetic distortions introduced by computers and other electronic devices and metal objects.
- We’re still calibration mode for the accelerometer. Send
#on
, which will move calibration to the next sensor, which is the magnetometer. - NOTE: This section stays here for reference, but you should use the newer "Extended magnetometer calibration (see next section) as it yields much better results! You can skip this and continue with the gyroscope.
- We'll try to find the minimum and maximum output values for the earth magnetic field on each axis. This basically works like calibrating the accelerometer, except the magnetic field of the earth does not point down straight. Depending on where on the planet you currently are, it points north-and-up (southern hemisphere) or north-and-down (northern hemisphere) at a certain angle. This angle is called inclination. Additionally there might be a tiny deviation from true geographic north, which is called declination. See Wikipedia. The following description assumes you’re calibrating the magnetometer on the northern hemisphere.
- Hold the board flat like a compass with the x-axis (remember: x-axis = forward, towards the connector holes) pointing north. Then begin to rotate the board around the east-west axis so it starts pointing down. Observe the x-maximum (the second value) in the Serial Monitor and you will notice when you aligned the board’s x-axis with the magnetic field of the earth. Stop rotating there and again tilt a little in every direction until the value does not get bigger any more.
- Do the same thing for the opposite side to get the x-minimum: first point north, then down.
- For the magnetometer we don’t need to reset with
#oc
between measurements. - Do the same thing for the z-axis (up/down) and the y-axis (left/right).
- NOTE: The rotation of the board around the axis you want to measure doesn’t matter, only that it points into the correct direction. E.g when you start measuring the z-axis, it doesn’t matter if the x-axis points up or down or left or right.
- You should now have something like this in your Serial Monitor:
magn x,y,z (min/max) = -564.00/656.00 -585.00/635.00 -550.00/564.00
this is the library
Razor-AHRS
razor-9dof-ahrs