forked from mprograms/QMC5883LCompass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mprograms#2 from TheNitek/master
Add calibration functions
- Loading branch information
Showing
5 changed files
with
161 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
=============================================================================================================== | ||
QMC5883LCompass.h Library XYZ Example Sketch | ||
Learn more at [https://github.com/mprograms/QMC5883LCompass] | ||
Generate calibration values for your QMC5883L | ||
=============================================================================================================== | ||
Release under the GNU General Public License v3 | ||
[https://www.gnu.org/licenses/gpl-3.0.en.html] | ||
=============================================================================================================== | ||
*/ | ||
#include <QMC5883LCompass.h> | ||
|
||
QMC5883LCompass compass; | ||
|
||
int calibrationData[3][2]; | ||
bool changed = false; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
compass.init(); | ||
|
||
Serial.println("Slowly move your magnetometer in all directions until the output does not change anymore"); | ||
Serial.println("Afterwards just copy the most recent output line into your sketch to use calibration data"); | ||
} | ||
|
||
void loop() { | ||
int x, y, z; | ||
|
||
// Read compass values | ||
compass.read(); | ||
|
||
// Return XYZ readings | ||
x = compass.getX(); | ||
y = compass.getY(); | ||
z = compass.getZ(); | ||
|
||
changed = false; | ||
|
||
if(x < calibrationData[0][0]) { | ||
calibrationData[0][0] = x; | ||
changed = true; | ||
} | ||
if(x > calibrationData[0][1]) { | ||
calibrationData[0][1] = x; | ||
changed = true; | ||
} | ||
|
||
if(y < calibrationData[1][0]) { | ||
calibrationData[1][0] = y; | ||
changed = true; | ||
} | ||
if(y > calibrationData[1][1]) { | ||
calibrationData[1][1] = y; | ||
changed = true; | ||
} | ||
|
||
if(z < calibrationData[2][0]) { | ||
calibrationData[2][0] = z; | ||
changed = true; | ||
} | ||
if(z > calibrationData[2][1]) { | ||
calibrationData[2][1] = z; | ||
changed = true; | ||
} | ||
|
||
if(changed) { | ||
Serial.print("compass.setCalibration("); | ||
Serial.print(calibrationData[0][0]); | ||
Serial.print(", "); | ||
Serial.print(calibrationData[0][1]); | ||
Serial.print(", "); | ||
Serial.print(calibrationData[1][0]); | ||
Serial.print(", "); | ||
Serial.print(calibrationData[1][1]); | ||
Serial.print(", "); | ||
Serial.print(calibrationData[2][0]); | ||
Serial.print(", "); | ||
Serial.print(calibrationData[2][1]); | ||
Serial.println(");"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters