In this video lesson we activate the QMC5883L 3-axis magnetometer on our GY-87 module. We show how to read the raw magnetic field strength in the x, y, and z axis. Your homework assignment will be to then calibrate the measurements such that you center the measured values around 0, and create a unit circle. This calibration will be very similar to what we did for the accelerometers a few weeks ago. This is the schematic we continue to use in this lesson:

This is the code we developed in todays lesson to read the raw data from the magnetometers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <Wire.h> #include <QMC5883LCompass.h> int x,y,z; Adafruit_MPU6050 mpu; QMC5883LCompass compass; void setup() { Serial.begin(115200); mpu.begin(); mpu.setI2CBypass(true); compass.init(); } void loop() { compass.read(); x = compass.getX(); y = compass.getY(); z = compass.getZ(); Serial.print(x); Serial.print(','); Serial.print(y); Serial.print(','); Serial.println(z); delay(100); } |