Magnetic Compass Product 4413 and 4479

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eddyhodak
 
Posts: 3
Joined: Thu Jan 26, 2023 9:28 pm

Magnetic Compass Product 4413 and 4479

Post by eddyhodak »

Keen to get electronic magnet compass functionality into my robotic cart project. However, the Adafruit products

Adafruit LSM303AGR Accelerometer Magnetometer - STEMMA QT Qwiic PID: 4413
$12.50

Adafruit Triple-axis Magnetometer - LIS3MDL - STEMMA QT / Qwiic PID: 4479
$14.95

Adafruit 6DoF Accelerometer and Gyroscope - STEMMA QT / Qwiic
Product ID: 4438

presents questions:
The PID 4413 does have both the 3 DOF Accel and Mag Field sensors and the suggested library LIS@MDL does have an example code producing magnet compass heading and calibration. The PID 4479 might need a 3 DOF Magnet field device but it is suggested to purchase PID 4438 6 DoF Accelerometer and Gyroscope with the PID 4479; however the suggested library does have an example code producing magnetic compass heading nor calibration. As I really want magnet compass heading in a 'tilt compensated' version, I think I must purchase a PID 4413 and use LIS2MDL Library for its compass and calibration example.

As I am extremely familiar with the Bosch BNO 055 and like it very much but I have not found a way to retain its calibration data so that upon a next power up I must complete the system calibration by 'waving in a figure 8" pattern. My robot cart is way too heavy to do that. I hope the ST Micro devices will store calibration and that is why I am looking at the Library LIS2MDL and the PID 4413 Black AGR breakout board.

Should I purchase a Black PID 4413 but also a PID 4438 and use the LIS2MDL library to get both calibrate and get compass reading - hopefully tilt compensated.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Magnetic Compass Product 4413 and 4479

Post by adafruit_support_mike »

The LSM303 would be the most effective device for a tilt-compensated compass. A gyro will tell you how fast the board is rotating, but the magnetometer reading will tell you that too.. just to lower resolution.

Be aware that the Earth's magnetic field is tilted steeply toward the ground in most places.

User avatar
eddyhodak
 
Posts: 3
Joined: Thu Jan 26, 2023 9:28 pm

Re: Magnetic Compass Product 4413 and 4479

Post by eddyhodak »

Can I assume that by the LSM303 you mean PID 4413?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Magnetic Compass Product 4413 and 4479

Post by adafruit_support_mike »

Yes.

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Magnetic Compass Product 4413 and 4479

Post by sj_remington »

You will probably want to implement a tilt-compensated compass. I glanced through the library code, and that does not seem to be implemented for the LSM303AGR (4413). I really like the vector math approach, as it is far simpler and less prone to typos, etc. than the typical trigonometric solution.

I use a modification of Pololu's code. Of course the magnetometer must be carefully calibrated in the final mounting place, otherwise the data will most likely be useless. This is the same problem as with the BNO055, except that the calibration should be a one-time effort.

Tilt-compensated compass code for the related sensor LSM9DS1, using the above approach, can be found here: https://github.com/jremington/LSM9DS1-AHRS

Warning: it is extremely important that the handedness of the data be corrected. The manufacturer-assigned X,Y,Z sensor axes on the LSM303AGR form a left-handed coordinate system. Invert (negate) the data from any one axis to fix that.

User avatar
eddyhodak
 
Posts: 3
Joined: Thu Jan 26, 2023 9:28 pm

Re: Magnetic Compass Product 4413 and 4479

Post by eddyhodak »

sj-remington: I thank you for this extended post to my questions. It will be very useful to sort out the calibration and thus accurate use of this compass:PID 4413. However, you describe use of the LSM9DS1 PID 4634 which I didn't even see as I didn't search for 9 DOF breakout board. I will have to investigate the differences between the two sensors using product sheets but perhaps you know. For example, with higher cost the LSM9DS1 about 3x is there an onchip DMP as there is on the Bosch BNO 055? And there is the accuracy of measurement issue. Please don't worry if you don't know as you have already offered a HUGE HELP with all this information. As a physicist, the often expressed concern for the maths is mildly humorous to me. Cheers, eddy

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Magnetic Compass Product 4413 and 4479

Post by sj_remington »

you describe use of the LSM9DS1
Yes, but heart of the tilt compensation algorithm does not depend on which sensor is used. Once you have corrected magnetometer and accelerometer measurements, in a right handed coordinate system, the rest of the code can be used unmodified.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”