I'm trying to use MPU9250/6500 to get xyz axis
the code I got from GitHub
#include "Wire.h"
#include "I2C.h"
#define MPU9250_IMU_ADDRESS 0x68
#define MPU9250_MAG_ADDRESS 0x0C
#define GYRO_FULL_SCALE_250_DPS 0x00
#define GYRO_FULL_SCALE_500_DPS 0x08
#define GYRO_FULL_SCALE_1000_DPS 0x10
#define GYRO_FULL_SCALE_2000_DPS 0x18
#define ACC_FULL_SCALE_2G 0x00
#define ACC_FULL_SCALE_4G 0x08
#define ACC_FULL_SCALE_8G 0x10
#define ACC_FULL_SCALE_16G 0x18
#define TEMPERATURE_OFFSET 21 // As defined in documentation
#define INTERVAL_MS_PRINT 1000
#define G 9.80665
struct gyroscope_raw {
int16_t x, y, z;
} gyroscope;
struct accelerometer_raw {
int16_t x, y, z;
} accelerometer;
struct magnetometer_raw {
int16_t x, y, z;
struct {
int8_t x, y, z;
} adjustment;
} magnetometer;
struct temperature_raw {
int16_t value;
} temperature;
struct {
struct {
float x, y, z;
} accelerometer, gyroscope, magnetometer;
float temperature;
} normalized;
unsigned long lastPrintMillis = 0;
void setup()
{
Wire.begin();
Serial.begin(115200);
I2CwriteByte(MPU9250_IMU_ADDRESS, 27, GYRO_FULL_SCALE_1000_DPS); // Configure gyroscope range
I2CwriteByte(MPU9250_IMU_ADDRESS, 28, ACC_FULL_SCALE_2G); // Configure accelerometer range
I2CwriteByte(MPU9250_IMU_ADDRESS, 55, 0x02); // Set by pass mode for the magnetometers
I2CwriteByte(MPU9250_IMU_ADDRESS, 56, 0x01); // Enable interrupt pin for raw data
setMagnetometerAdjustmentValues();
//Start magnetometer
I2CwriteByte(MPU9250_MAG_ADDRESS, 0x0A, 0x12); // Request continuous magnetometer measurements in 16 bits (mode 1)
}
void loop()
{
unsigned long currentMillis = millis();
if (isImuReady()) {
readRawImu();
normalize(gyroscope);
normalize(accelerometer);
normalize(temperature);
}
if (isMagnetometerReady()) {
readRawMagnetometer();
normalize(magnetometer);
}
if (currentMillis - lastPrintMillis > INTERVAL_MS_PRINT) {
Serial.print("TEMP:\t");
Serial.print(normalized.temperature, 2);
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.print("C");
Serial.println();
Serial.print("GYR (");
Serial.print("\xC2\xB0"); //Print degree symbol
Serial.print("/s):\t");
Serial.print(normalized.gyroscope.x, 3);
Serial.print("\t\t");
Serial.print(normalized.gyroscope.y, 3);
Serial.print("\t\t");
Serial.print(normalized.gyroscope.z, 3);
Serial.println();
Serial.print("ACC (m/s^2):\t");
Serial.print(normalized.accelerometer.x, 3);
Serial.print("\t\t");
Serial.print(normalized.accelerometer.y, 3);
Serial.print("\t\t");
Serial.print(normalized.accelerometer.z, 3);
Serial.println();
Serial.print("MAG (");
Serial.print("\xce\xbc"); //Print micro symbol
Serial.print("T):\t");
Serial.print(normalized.magnetometer.x, 3);
Serial.print("\t\t");
Serial.print(normalized.magnetometer.y, 3);
Serial.print("\t\t");
Serial.print(normalized.magnetometer.z, 3);
Serial.println();
Serial.println();
lastPrintMillis = currentMillis;
}
}
this is the error message
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino: In function 'void setup()':
xyz:64:3: error: 'setMagnetometerAdjustmentValues' was not declared in this scope
setMagnetometerAdjustmentValues();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino: In function 'void loop()':
xyz:74:7: error: 'isImuReady' was not declared in this scope
if (isImuReady()) {
^~~~~~~~~~
xyz:75:5: error: 'readRawImu' was not declared in this scope
readRawImu();
^~~~~~~~~~
xyz:77:5: error: 'normalize' was not declared in this scope
normalize(gyroscope);
^~~~~~~~~
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino:77:5: note: suggested alternative: 'normalized'
normalize(gyroscope);
^~~~~~~~~
normalized
xyz:82:7: error: 'isMagnetometerReady' was not declared in this scope
if (isMagnetometerReady()) {
^~~~~~~~~~~~~~~~~~~
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino:82:7: note: suggested alternative: 'magnetometer_raw'
if (isMagnetometerReady()) {
^~~~~~~~~~~~~~~~~~~
magnetometer_raw
xyz:83:5: error: 'readRawMagnetometer' was not declared in this scope
readRawMagnetometer();
^~~~~~~~~~~~~~~~~~~
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino:83:5: note: suggested alternative: 'magnetometer'
readRawMagnetometer();
^~~~~~~~~~~~~~~~~~~
magnetometer
xyz:85:5: error: 'normalize' was not declared in this scope
normalize(magnetometer);
^~~~~~~~~
C:\Users\Cloud\OneDrive\Desktop\master degree\arduino code\xyz\xyz.ino:85:5: note: suggested alternative: 'normalized'
normalize(magnetometer);
^~~~~~~~~
normalized
exit status 1
'setMagnetometerAdjustmentValues' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.