Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years ago.
Using the MAG3110 magnetometer on FRDM KL46z
I am trying to using the MAG3110 magnetometer on the FRDM KL46z Board. So far I have managed to output the X, Y, Z values of the magnetometer onto serial but can't figure out the significance of those readings. Can someone guide me to the appropriate resources?
Question relating to:
1 Answer
10 years ago.
If i'm not wrong, this sensor outputs uT (micro Tesla) raw values for each ot the 3 axis, the unit value of the output is 0.1uT There is nothing special you can get out of a mag sensor alone, just a not reliable north position.
#define M_PI 3.14159265358979323846f //convert to real world values uT_X = (float)Raw_X * 0.1; uT_Y = (float)Raw_Y * 0.1; uT_Z = (float)Raw_Z * 0.1; //get heading in radians float heading = atan2(uT_Y, uT_X); if(heading < 0) heading += 2*M_PI; if(heading > 2*M_PI) heading -= 2*M_PI; //radians to degree printf("Heading= %4.2f ", heading * 180/ M_PI);
Then, you'll see lots of noise and a not reliable heading direction, that's because: - you have magnets near the sensor, that's called hard iron distorsion (speakers, cell phones...) - you have ferromagnetic metals around, that's calles soft-iron distorsion (pc monitor, pc case....) - your sensor is not in perfect plane position, you need an accelerometer to compensate that....then you'll see that quick movement of the accelerometer will make wrong heading as "spikes", so you'll need a gyro to filter out the "shakings".
I cannot suggest a single place to get some reading, i can suggest to google for soft-iron, hard-iron, tilt compensated compass, AHRS, IMU. Anyway a single magnetometer is not enought to have a good heading.