Inside the LSM9Ds1 IMU on the Nano 33 BLE board is a three axis magnetometer. Although it is packaged inside the same chip as the accelerometer/gyro, it is a physically distinct device with its own address and registers. The purpose of a magnetometer is to measure magnetic field strength. It can be used as the basis for a compass that will allow you to get a pretty good estimate of magnetic North.
Earth’s Magnetic Field
You almost certainly know that the Earth has magnetic field and everybody is familiar with the geographic terms North, South, East and West. If you have a good old fashioned compass, it will have a needle that points to Geographic North. The Geographic North Pole is ‘up’ above Canada, Norway and Russia somewhere. Opposite is the Geographic South Pole somewhere in Antarctica.
Most likely, you are aware that bar magnets and other magnet shapes have North and South poles and that a magnetic compass is just a light weight bar magnet suspended so that it can freely rotate. One end of the magnet points to the Earth’s Geographic North Pole
Now for the potentially confusing part. The Earth’s Geographic North Pole is actually a magnetic South Pole. Suddenly you doubt everything you thought you knew. If you take a small bar magnet and float it on a piece of cork, that magnet’s North pole will point to the Earths Geographic North Pole. That is, a definition of a magnets pole is in terms of whether it is attracted to the Earth’s North or South Pole.
Armed with this knowledge, you can use a compass to correctly mark the polarity of any simple magnets that you have around the house.
BTW – this will not work with ‘fridge magnets, magnetic labels , magnetic paper and all sorts of other things. They are magnetised in stripes so do not have a clear North and South Pole.
This picture comes from http://www.ifa.hawaii.edu/~barnes/ast110_06/ which is the earliest reference I could find. No idea who owns it.
Not only is the Magnetic Pole not in the same place as the Geographic Pole, it has a tendency to wander about. The difference in the bearing to the Magnetic and Geographic poles is called the Magnetic Declination. For my home location, the Declination is about 1.6º West.
In the figure above, you can see lines of magnetic flux. By convention, these flow from magnetic North to magnetic South. It should also be clear that these flux lines do not lie parallel to the Earth’s surface because the location of the centre of each magnetic pole is somewhere inside the Earth, not on the surface. If you were somewhere on the equator, the flux lines are approximately horizontal. As you travel further away from the equator, the flux lines are tilted downwards towards the magnetic poles.
This tilting is called the Magnetic Inclination. For my home location, the angle of inclination is about 67.82º.
You can look up your current Magnetic Declination, Inclination and field strength at https://www.magnetic-declination.com/
The magnetometer inside the LSM9DS1 is quite sensitive and its readings will be affected by any magnetic fields nearby. Pretty much any Iron object is likely to have at least a small magnetic field associated with it. Even something like a steel screw will eventually become slightly magnetic if left in one place for very long. Another source of strong magnetic fields is any wire that is carrying an electric current. While the currents in the conductors on a PCB do not create a very large field, it is still there. Much more significant will be the field generated by large coils such as are found in electric motors. Indeed, the more powerful the motor, the larger will be the magnetic field.
- Adventures in Science: Using a Magnetometer as a Compass
NXP MAG3110 Magnetometer
- NXP AN4248, Implementing a Tilt-Compensated E-Compass Using Accelerometer and Magnetometer Sensors
- NXP AN4246, Calibrating an eCompass in the Presence of Hard- and Soft-Iron Interference
- NXP Freescale MAG3110 Three-Axis, Digital Magnetometer – Data Sheet
- NXP MAG3110 Frequently Asked Questions – Supporting Information