How to Calibrate a Magnetometer | Digi-Key Electronics

Sdílet
Vložit
  • čas přidán 30. 07. 2024
  • Magnetometers are fantastic sensors that allow you to measure the strength and direction of magnetic fields. With a little bit of math, they can be used as digital compasses to find your absolute orientation on Earth. However, they are very susceptible to extraneous magnetic fields (hard iron distortions) and nearby ferrous materials (soft iron distortions).
    In this video, we construct a basic digital compass using a magnetometer, which measures the strength and direction of the Earth’s magnetic field. We demonstrate possible distortion effects and show how to perform hard iron and soft iron calibration.
    A written version of this guide can be found here: www.digikey.com/en/maker/proj...
    Example code shown in the video: github.com/ShawnHymel/mag-cal...
    Adafruit SensorLab: github.com/adafruit/Adafruit_...
    PJRC MotionCal: www.pjrc.com/store/prop_shiel...
    NOAA magnetic declination calculator: www.ngdc.noaa.gov/geomag/decl...
    Due to the moving, liquid metal in the outer core, the Earth acts like a giant magnet. While the magnetic field produced is not very strong, we can still detect it with permanent magnets (how a needle compass works) or magnetometers. If we find the direction of the field, we can find the direction of the magnetic north and south poles. From there, we can calculate our absolute heading.
    However, nearby permanent magnets and electric currents produce magnetic fields that can interfere with these readings. This is known as “hard iron distortion.” We can sample the magnetic field strength around the sensor to create simple X, Y, and Z offset values that we subtract from our raw readings.
    Additionally, nearby ferrous materials can distort the magnetic fields (known as “soft iron distortions”). We can sample the raw X, Y, and Z values and analytically find the scaling factors to account for this type of distortion. If you’d like to dig into the math, we recommend checking out this application note: www.nxp.com/docs/en/applicati...
    In the video, we show how to perform the magnetometer calibration process using Adafruit SensorLab and PJRC MotionCal. We then use the offset values from that program to create a calibrated digital compass. Finally, we include magnetic declination so you can see how to convert from a magnetic heading to a geographic heading.
    Product Links:
    Adafruit Feather M0 Basic - www.digikey.com/en/products/d...
    Adafruit Triple-Axis Magnetometer LIS3MDL - www.digikey.com/en/products/d...
    Adafruit STEMMA JST PH 4-pin to male header cable - www.digikey.com/en/products/d...
    Related Videos:
    Magnetometer Tutorial - www.digikey.com/en/videos/n/n...
    3D Magnetic Field Sensor IC (Magnetometer) - www.digikey.com/en/videos/m/m...
    Related Project Links:
    How to Calibrate a Magnetometer - www.digikey.com/en/maker/proj...
    Related Articles:
    Adafruit Magnetometer Calibration Tutorial - learn.adafruit.com/adafruit-s...
    How to Calibrate a Magnetometer? - www.appelsiini.net/2018/calib...
    Tutorial: How to calibrate a compass (and accelerometer) with Arduino - thecavepearlproject.org/2015/...
    Magnetometer Hard & Soft Iron Calibration - www.vectornav.com/resources/i...
    Calibrate an eCompass in the Presence of Hard- and Soft-Iron Interference - www.nxp.com/docs/en/applicati...
    Learn more:
    Maker.io - www.digikey.com/en/maker
    Digi-Key’s Blog - TheCircuit www.digikey.com/en/blog
    Connect with Digi-Key on Facebook / digikey.electronics
    And follow us on Twitter / digikey
  • Věda a technologie

Komentáře • 38

  • @isojed
    @isojed Před 2 lety +6

    Well done.
    Brings back memories of the ArduPilot early days when IMU where implemented. Good source btw.

  • @John_Smith__
    @John_Smith__ Před 2 lety +5

    Great video, very very useful for drone builders. Thanks for sharing!

  • @JurassicJenkins
    @JurassicJenkins Před 2 lety

    Thanks for a complete explanation with visuals. Much appreciated 🎈

  • @martinbengtsson3652
    @martinbengtsson3652 Před 2 lety

    Garrett Evans Wow thank you Garrett, you've made my day!

  • @marcinb388
    @marcinb388 Před 11 měsíci

    Very good explanation, thanks

  • @evanbarnes9984
    @evanbarnes9984 Před 2 lety +1

    Very helpful!

  • @AlbertRei3424
    @AlbertRei3424 Před 2 lety

    Awesome Shawn

  • @Sembazuru
    @Sembazuru Před 2 lety

    Would the tilt compensation you briefly mention at the end also account for the Earth's magnetic flux lines being more vertical in reference to the ground the closer you get to the magnetic poles?

  • @nakulsingh8444
    @nakulsingh8444 Před 2 lety

    Very helpful.

  • @Nickle314
    @Nickle314 Před 2 lety +1

    Correct on the ellipsoid.
    What I think is a better approach is continuous calibration. Every time you get a vector in a particular direction, store the scale. Eventually you get a full sphere of vectors.
    I don't think its a good idea having a completely separate calibration and use mode

  • @JustAnotherAlchemist
    @JustAnotherAlchemist Před 6 měsíci

    > @12:10: "Along one particular axis."
    From what I understand, the axis of the ellipse will not necessarily be parallel to any particular magnetometer axis, but could be any possible rotation.
    Consider a large MLCC (They have Nickel terminals) directly off (and too close to) one corner of the magnetometer package. This would cause a concentration of magnetic flux that is more or less directly diagonal to some two axis of the chip. This would, in turn, cause higher apparent magnetic intensity aligned with the diagonal and thus the major axis of the ellipse would also be aligned with the diagonal.

  • @nakulsingh8444
    @nakulsingh8444 Před 2 lety +6

    Plz make video on tilt compensation also.

    • @ShawnHymel
      @ShawnHymel Před 2 lety +2

      Good to know there is interest! I can definitely see how tilt compensation would be useful.

    • @evanbarnes9984
      @evanbarnes9984 Před 2 lety

      @@ShawnHymel I'm also interested in tilt compensation! I'm working on making my own flight instrument for paragliding, and with the way my flight deck will hold the instrument, it will have to be tilt compensated. Thanks for this video, it's super helpful!

    • @FlyGamingChannel
      @FlyGamingChannel Před rokem

      That would be a great video

  • @no5x937
    @no5x937 Před 2 lety

    What magnetometer would you recommend for a 3-axis (azimuth, elevation, tilt) Satellite Antenna Tracker? Would it benefit from an accelerometer?

  • @ericchristian2243
    @ericchristian2243 Před rokem

    Great video, I followed all instructions with this video and Adafruit configuration notes from their website and the only sketch that I could get to upload was the Blink sketch. How did you manage to upload imucal nosave? I've tried everything and get Error compiling for Adafruit Feather M0 (SAMD21). If you can help this would be great.

  • @leoakimono3631
    @leoakimono3631 Před rokem +1

    I have a question, it seems many tuts about hard and soft iron distortion is not quite accurate.
    As you can see, you subtract hard iron Vector, and left multiply soft iron Matrix, BASED ON YOUR IMU'S COORD SYS, which means both distortions are coming from the magnetic materials ON YOUR CHIP. Which means where ever you go, your calibration works. what you mentioned at 18:30, means assemble everything up, then calib right?
    The distortion from the enviroment, at a certain position, will only be a vector add to the earth mag field vector. And cuz they changes in diffrent position, it's a none linear transformation based on world axis. you simply can not calib them.

  • @nadunnilupulliyanawaduge6462

    Think I want to neglect the earth magnetic field by placing a strong magnet. Do I need to calibrate the hard iron and soft iron calibration. Another thing is I want to know whether the magnetometer behave as it is soclose to the magnet ?Because I didn't get desired behavior from the magnet.

  • @user-hb3cw2ez9w
    @user-hb3cw2ez9w Před 4 měsíci

    It would be nice if the Git page was still available. And then there seems so be some typos in the code provided with the writeup.

  • @AlbertRei3424
    @AlbertRei3424 Před 2 lety +1

    I can't download MotionCal, anyone has a link please ?

  • @sijinahi3675
    @sijinahi3675 Před rokem +1

    how to validate the x, y, z,value if its correct or not

  • @Jkauppa
    @Jkauppa Před 2 lety

    try making a simple inertial measurement unit (accelerometer) wired mouse, no light/laser or ball sensors

  • @keithschaub7863
    @keithschaub7863 Před 7 měsíci

    so my question is, if you only care about relative difference, do you still need to calibrate - that's an awful lot of trouble to go through. I just want it to tell me that the heading has changed by a few degrees, and then use that to update the car steering to put it back on course. But, I find that even calibrated, it isn't repeatable, or at least not that I can see.

  • @marwankhaledkasem9335
    @marwankhaledkasem9335 Před 2 lety

    great thank you but can you make course arm (spi, i2c, ......) that will be great please😊😊

  • @quigs666
    @quigs666 Před 6 měsíci

    Has anybody gotten MotionCal (or the Adafruit Jupyter notebook) to work? I tried Windows, Linux, and Mac and didn't get anywhere.

  • @keithschaub7863
    @keithschaub7863 Před 7 měsíci

    Can you confirm…the compass in your smartphone is calibrated at the factory? Cuz when you buy a new iPhone, it just works when you power on.

  • @alkaline3mc
    @alkaline3mc Před rokem

    The PJRC MotionCal software download link (Windows) does not appear to be functional. I supposed there's still the Adafruit Jupyter notebook but it's kinda a bummer.

    • @cyamite3435
      @cyamite3435 Před 8 měsíci

      I have the same problem, any way to fix that ?

    • @dimir1463
      @dimir1463 Před 6 měsíci

      ​@@cyamite3435 I was able to download it using the Edge browser. There is a popup when I downloaded it using edge that didn't appear when I used chrome or brave. The popup is some sort of security message, but you can click the popup and proceed with the download.

  • @lker6501
    @lker6501 Před rokem +1

    Motion cal doesnt respond

    • @lker6501
      @lker6501 Před rokem

      The problem was that i was that the teeny was spending to much information to motion cal , I just added a 50ms delay in the nosave program and it worked fantastic

  • @Nickle314
    @Nickle314 Před 2 lety

    8:53 into the video.
    Raw shows -277 Uni shows -27.78
    That looks like there is a rounding issue. -27.78 rounded to 3 dec pl is -27.8 not -27.7 which is what you would expect from the raw

    • @a5daw218d
      @a5daw218d Před 5 měsíci

      depend if your round(), cast on int or others stuff

  • @MyLife-lm3zo
    @MyLife-lm3zo Před 10 měsíci

    What if the magnetometer is hooked up to a raspberry pi?

  • @HARSHSHAH-nu9pu
    @HARSHSHAH-nu9pu Před 9 dny

    also plese attached code shown in video mag_calibration_test.ino