{"id":21752,"date":"2017-08-23T08:01:31","date_gmt":"2017-08-23T15:01:31","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=21752"},"modified":"2021-06-10T16:30:34","modified_gmt":"2021-06-10T23:30:34","slug":"how-to-calibrate-your-magnetometer-tutorial","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/how-to-calibrate-your-magnetometer-tutorial\/","title":{"rendered":"How to Calibrate your Magnetometer &#8211; Tutorial"},"content":{"rendered":"<figure style=\"width: 290px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/cdn6.bigcommerce.com\/s-7gavg\/products\/582\/images\/4654\/Pmod_CMPS2_-_Oblique_-_600__66698.1500408323.1280.1280.png?c=2\" alt=\"Pmod CMPS2, oblique view.\" width=\"290\" height=\"290\" \/><figcaption class=\"wp-caption-text\"><em>Pmod CMPS2 3-axis digital magnetometer\/compass.<\/em><\/figcaption><\/figure>\n<p>In a <a href=\"https:\/\/digilent.com\/blog\/how-to-get-useful-data-from-your-magnetometer\/\">previous post,<\/a> we discussed how to start getting data from your magnetometer, using the Pmods CMPS2 as an example. The Pmod CMPS2 uses the I2C communication protocol so instructions were given in psuedo code for an I2C controller. The same applies here.<\/p>\n<p>Calibrating your magnetometer is usually the hardest part about using this type of sensor and successfully turning it into a digital compass. The instructions are below, but brace yourself because it&#8217;s a long one.<\/p>\n<p><strong>Calibration<\/strong><\/p>\n<p>To calibrate the magnetometer, the offset associated with the magnetic sensors and the environment needs to be calculated and removed from future measurements. The internal offset can be calculated and accounted for through the following method:<\/p>\n<dl class=\"outliner outliner-nopopup outliner-js outliner-open\">\n<dd>\n<ol>\n<li class=\"level1\">\n<div class=\"li\">Power on the Pmod CMPS2 and wait for 10 mS before further operation.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to recharge the capacitor to prepare for the SET action.<\/p>\n<pre class=\"code\">I2CWrite(0x80); \/\/0x80 refills the capacitor<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 50 mS to allow the Pmod CMPS2 to finish preparing.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to start a SET action.<\/p>\n<pre class=\"code\">I2CWrite(0x20); \/\/0x20 starts the SET action<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 1 mS to allow the Pmod CMPS2 to finish the SET action.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to take a measurement by setting bit 0 high followed by a STOP bit.<\/p>\n<pre class=\"code\">I2CWrite(0x01); \/\/0x01 initiates a data acquisition<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 7.92 mS by default to allow the Pmod CMPS2 to finish collecting data.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Status Register (0x03) as the register to read<\/p>\n<pre class=\"code\">I2CWrite(0x03); \/\/indicate you wish to interact with address 0x03<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a read bit<\/p>\n<pre class=\"code\">I2CBegin(0xA1); \/\/device ID 0x30 with a read (1) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Cycle the SCL line to receive the Status Register data on the SDA line. Keep reading the Status Register by repeating steps 8 through 13 until bit 0 is set to &#8216;1&#8217;, indicating that the data on all 3 axes as available to be read.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the first register address corresponding to Xout LSB (0x00) as the register to be read.<\/p>\n<pre class=\"code\">I2CWrite(0x00); \/\/address 0x00 as the first register to be read<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a read bit<\/p>\n<pre class=\"code\">I2CBegin(0xA1); \/\/device ID 0x30 with a read (1) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Cycle the SCL line to receive the data bits from the X, Y, and Z registers in the SDA line, providing an ACK between each data byte. The Pmod CMPS2 address pointer automatically moves to each consecutive byte. End the communication by sending a NACK followed by a STOP command.<\/p>\n<pre class=\"code\">I2CReadMultiple(6); \/\/read six bytes, sending an ACK to the slave device between each byte received\r\n                                   and a NACK after the last byte<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Each of the readings will contain the external magnetic field\u00a0<em>H<\/em>\u00a0in addition to offset associated with the current put through the coil by the SET action.<br \/>\n<span id=\"MathJax-Element-1-Frame\" class=\"mjx-chtml MathJax_CHTML\" role=\"presentation\"><span id=\"MJXc-Node-1\" class=\"mjx-math\"><span id=\"MJXc-Node-2\" class=\"mjx-mrow\"><span id=\"MJXc-Node-3\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-4\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-5\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-6\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">p<\/span><\/span><span id=\"MJXc-Node-7\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-8\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-9\" class=\"mjx-mn\"><span class=\"mjx-char MJXc-TeX-main-R\">1<\/span><\/span><span id=\"MJXc-Node-10\" class=\"mjx-mo MJXc-space3\"><span class=\"mjx-char MJXc-TeX-main-R\">=<\/span><\/span><span id=\"MJXc-Node-11\" class=\"mjx-mo MJXc-space3\"><span class=\"mjx-char MJXc-TeX-main-R\">+<\/span><\/span><span id=\"MJXc-Node-12\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">H<\/span><\/span><span id=\"MJXc-Node-13\" class=\"mjx-mo MJXc-space2\"><span class=\"mjx-char MJXc-TeX-main-R\">+<\/span><\/span><span id=\"MJXc-Node-14\" class=\"mjx-mi MJXc-space2\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-15\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-16\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-17\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">s<\/span><\/span><span id=\"MJXc-Node-18\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">e<\/span><\/span><span id=\"MJXc-Node-19\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">Output1=+H+Offset<\/span><\/span><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Now a RESET action will be performed to reverse the magnetization for the sensing resistors to get the inverse offset value.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to recharge the capacitor to prepare for the RESET action.<\/p>\n<pre class=\"code\">I2CWrite(0x80); \/\/0x80 refills the capacitor<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 50 mS to allow the Pmod CMPS2 to finish preparing.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to start a RESET action.<\/p>\n<pre class=\"code\">I2CWrite(0x40); \/\/0x40 starts the RESET action<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 1 mS to allow the Pmod CMPS2 to finish the SET action.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Internal Control Register 0 (address 0x07) as the register to communicate with<\/p>\n<pre class=\"code\">I2CWrite(0x07); \/\/address 0x07 corresponds to Control Register 0<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Write the command to take a measurement by setting bit 0 high followed by a STOP bit.<\/p>\n<pre class=\"code\">I2CWrite(0x01); \/\/0x01 initiates a data acquisition<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 7.92 mS by default to allow the Pmod CMPS2 to finish collecting data.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Status Register (0x03) as the register to read<\/p>\n<pre class=\"code\">I2CWrite(0x03); \/\/indicate you wish to interact with address 0x03<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a read bit<\/p>\n<pre class=\"code\">I2CBegin(0xA1); \/\/device ID 0x30 with a read (1) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Cycle the SCL line to receive the Status Register data on the SDA line. Keep reading the Status Register by repeating steps 8 through 13 until bit 0 is set to &#8216;1&#8217;, indicating that the data on all 3 axes as available to be read.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0xA0); \/\/device ID 0x30 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the first register address corresponding to Xout LSB (0x00) as the register to be read.<\/p>\n<pre class=\"code\">I2CWrite(0x00); \/\/address 0x00 as the first register to be read<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a read bit<\/p>\n<pre class=\"code\">I2CBegin(0xA1); \/\/device ID 0x30 with a read (1) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod CMPS2.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Cycle the SCL line to receive the data bits from the X, Y, and Z registers in the SDA line, providing an ACK between each data byte. The Pmod CMPS2 address pointer automatically moves to each consecutive byte. End the communication by sending a NACK followed by a STOP command.<\/p>\n<pre class=\"code\">I2CReadMultiple(6); \/\/read six bytes, sending an ACK to the slave device between each byte received\r\n                                   and a NACK after the last byte<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Each of the readings will contain the external magnetic field\u00a0<em>H<\/em>\u00a0in addition to offset associated with the current put through the coil by the RESET action.<\/div>\n<div class=\"li\"><span id=\"MathJax-Element-2-Frame\" class=\"mjx-chtml MathJax_CHTML\" role=\"presentation\"><span id=\"MJXc-Node-20\" class=\"mjx-math\"><span id=\"MJXc-Node-21\" class=\"mjx-mrow\"><span id=\"MJXc-Node-22\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-23\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-24\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-25\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">p<\/span><\/span><span id=\"MJXc-Node-26\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-27\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-28\" class=\"mjx-mn\"><span class=\"mjx-char MJXc-TeX-main-R\">2\u00a0<\/span><\/span><span id=\"MJXc-Node-29\" class=\"mjx-mo MJXc-space3\"><span class=\"mjx-char MJXc-TeX-main-R\">=\u00a0<\/span><\/span><span id=\"MJXc-Node-30\" class=\"mjx-mo MJXc-space3\"><span class=\"mjx-char MJXc-TeX-main-R\">\u2212<\/span><\/span><span id=\"MJXc-Node-31\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">H<\/span><\/span><span id=\"MJXc-Node-32\" class=\"mjx-mo MJXc-space2\"><span class=\"mjx-char MJXc-TeX-main-R\">+<\/span><\/span><span id=\"MJXc-Node-33\" class=\"mjx-mi MJXc-space2\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-34\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-35\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-36\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">s<\/span><\/span><span id=\"MJXc-Node-37\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">e<\/span><\/span><span id=\"MJXc-Node-38\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><\/span><\/span><\/span><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">The offset associated with the device can be calculated and then subtracted from future measurements to obtain the actual magnetic field.<\/div>\n<div class=\"li\"><span id=\"MathJax-Element-3-Frame\" class=\"mjx-chtml MathJax_CHTML\" role=\"presentation\"><span id=\"MJXc-Node-39\" class=\"mjx-math\"><span id=\"MJXc-Node-40\" class=\"mjx-mrow\"><span id=\"MJXc-Node-41\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-42\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-43\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">f<\/span><\/span><span id=\"MJXc-Node-44\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">s<\/span><\/span><span id=\"MJXc-Node-45\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">e<\/span><\/span><span id=\"MJXc-Node-46\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t\u00a0<\/span><\/span><span id=\"MJXc-Node-47\" class=\"mjx-mo MJXc-space3\"><span class=\"mjx-char MJXc-TeX-main-R\">= (<\/span><\/span><span id=\"MJXc-Node-48\" class=\"mjx-mstyle MJXc-space3\"><span id=\"MJXc-Node-49\" class=\"mjx-mrow\"><span id=\"MJXc-Node-50\" class=\"mjx-mfrac\"><span class=\"mjx-box MJXc-stacked\"><span class=\"mjx-numerator\"><span id=\"MJXc-Node-51\" class=\"mjx-mrow\"><span id=\"MJXc-Node-52\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-53\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-54\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-55\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">p<\/span><\/span><span id=\"MJXc-Node-56\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-57\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-58\" class=\"mjx-mn\"><span class=\"mjx-char MJXc-TeX-main-R\">1<\/span><\/span><span id=\"MJXc-Node-59\" class=\"mjx-mo MJXc-space2\"><span class=\"mjx-char MJXc-TeX-main-R\">+<\/span><\/span><span id=\"MJXc-Node-60\" class=\"mjx-mi MJXc-space2\"><span class=\"mjx-char MJXc-TeX-math-I\">O<\/span><\/span><span id=\"MJXc-Node-61\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-62\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-63\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">p<\/span><\/span><span id=\"MJXc-Node-64\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">u<\/span><\/span><span id=\"MJXc-Node-65\" class=\"mjx-mi\"><span class=\"mjx-char MJXc-TeX-math-I\">t<\/span><\/span><span id=\"MJXc-Node-66\" class=\"mjx-mn\"><span class=\"mjx-char MJXc-TeX-main-R\">2)\/<\/span><\/span><\/span><\/span><span class=\"mjx-denominator\"><span id=\"MJXc-Node-67\" class=\"mjx-mn\"><span class=\"mjx-char MJXc-TeX-main-R\">2<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<\/li>\n<\/ol>\n<\/dd>\n<\/dl>\n<p>The other method of calibration is to remove the hard iron bias introduced to the magnetometer by the surrounding environment by measuring (either continually or for a set time) all of the possible magnetometer readings in a Cartesian sphere and keeping track of the highest and lowest readings for each axis. The offset can then be calculated in the same fashion as described above with the SET and RESET actions. The advantage of this method is when the Pmod CMPS2 is continually changing locations or when other external magnetic fields may be introduced into the test environment.<\/p>\n<p>Don&#8217;t forget, the data also needs to be converted from units of Gauss into a proper compass heading. A future post will describe this in detail, or you can visit the Pmod <a href=\"https:\/\/digilent.com\/reference\/pmod\/pmodcmps2\/reference-manual\">CMPS2 reference manual.<\/a><\/p>\n<p>If you&#8217;d like to see some example code written in the Arduino IDE for how we acquire, calibrate and convert data from the Pmod CMPS2, see the Pmod CMPS2\u00a0<a href=\"https:\/\/digilent.com\/reference\/pmod\/pmodcmps2\/start\">Resource Center<\/a>.<\/p>\n<p>For questions or comments, please post in the comment section below or visit the <a href=\"https:\/\/forum.digilent.com\/\">Digilent Forum!<\/a><\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-21752 jlk' data-task='like' data-post_id='21752' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-21752 lc'>+2<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-21752 jlk' data-task='unlike' data-post_id='21752' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-21752 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-21752 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>We continue with our Pmod CMPS2 tutorial with this calibration guide!<\/p>\n","protected":false},"author":26,"featured_media":21402,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,1563],"tags":[],"ppma_author":[4491],"class_list":["post-21752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-expansion-modules","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/07\/Pmodcmps2-walkaroud-image.png","authors":[{"term_id":4491,"user_id":26,"is_guest":0,"slug":"talesab","display_name":"Talesa Bleything","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/7445e0f9a1a578bd8aca1528d6ed4c8a?s=96&d=mm&r=g","author_category":"","user_url":"","last_name":"Bleything","last_name_2":"","first_name":"Talesa","first_name_2":"","job_title":"","description":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/21752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=21752"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/21752\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/21402"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=21752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=21752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=21752"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=21752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}