Skip to content

Commit

Permalink
Fix MPU9250 Mag Offset bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Heltec-Aaron-Lee committed Nov 19, 2019
1 parent b438d2e commit f3e2a3b
Showing 1 changed file with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
#include <MPU9250_asukiaaa.h>

#ifdef _ESP32_HAL_I2C_H_
#define SDA_PIN 21
#define SCL_PIN 22
#endif
/* Heltec Automation MPU9520 Sensors test example
*
* Function:
* 9-axis sensor
*
* Description:
* 1.The MPU9250 integrates a 3-axis gyroscope, a 3-axis accelerometer,
* and a 3-axis magnetometer. The output is 16-bit digital.
*
* 2. Data can be exchanged via the Integrated Circuit Bus (IIC) interface
* and the microcontroller with a transfer rate of up to 400 kHz / s.
*
* 3. The accelerometer's measurement range is up to ??16g (g is gravitational
* acceleration), and the static measurement accuracy is high.
*
* 4. The magnetometer uses a high-intensity Hall-type sensor for data acquisition.
* The magnetic induction measurement range is ??4800??T, which can be used for auxiliary
* measurement of yaw angle.
*
* 5.The MPU9250's built-in digital motion processor (DMP: Hardware Motion Processor)
* hardware acceleration engine integrates nine-axis sensor data and outputs
* complete 9-axis fusion calculation data to the application.
*
* HelTec AutoMation, Chengdu, China
* www.heltec.org
*
* this project also realess in GitHub:
* https://github.com/HelTecAutomation/ASR650x-Arduino
*
* MPU9250 Get Mag Offset original project available here: https://github.com/asukiaaa/MPU9250_asukiaaa
*/

#include <MPU9250.h>

#define CALIB_SEC 20

MPU9250_asukiaaa mySensor;
MPU9250 mySensor;

uint8_t sensorId;
float mDirection, mX, mY, mZ;
Expand All @@ -17,12 +44,6 @@ void setup() {
while(!Serial);
Serial.println("started");

#ifdef _ESP32_HAL_I2C_H_ // For ESP32
Wire.begin(SDA_PIN, SCL_PIN); // SDA, SCL
#else
Wire.begin();
#endif

mySensor.setWire(&Wire);
while (mySensor.readId(&sensorId) != 0) {
Serial.println("Cannot find device to read sensorId");
Expand All @@ -38,7 +59,7 @@ void setup() {
Serial.println("Finished setting offset values.");
}

void setMagMinMaxAndSetOffset(MPU9250_asukiaaa* sensor, int seconds) {
void setMagMinMaxAndSetOffset(MPU9250* sensor, int seconds) {
unsigned long calibStartAt = millis();
float magX, magXMin, magXMax, magY, magYMin, magYMax, magZ, magZMin, magZMax;

Expand Down Expand Up @@ -85,4 +106,4 @@ void loop() {
Serial.println("at " + String(millis()) + "ms");
Serial.println(""); // Add an empty line
delay(500);
}
}

0 comments on commit f3e2a3b

Please sign in to comment.