Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not GETTING magnetometer data! #27

Open
andreevnikola opened this issue Jun 17, 2023 · 1 comment
Open

Not GETTING magnetometer data! #27

andreevnikola opened this issue Jun 17, 2023 · 1 comment

Comments

@andreevnikola
Copy link

andreevnikola commented Jun 17, 2023

Everything is implemented right. I am getting data from every other sensor but the magnetometer is ust stucked at:
image

Here is my CODE:

#include "IMU.h"

IMU::IMU()
{
    Wire.begin();

    pinMode(G_LED_PORT, OUTPUT);
    pinMode(BUZZER1_PORT, OUTPUT);

    setWire(&Wire);
    beginAccel();
    beginGyro();
    beginMag();

    accelUpdate();
    gyroUpdate();

    // CALIBRATE SENSORs
    Serial.println("PREPARE FOR CALIBRAION!");
    tone(BUZZER1_PORT, 10000);
    digitalWrite(G_LED_PORT, HIGH);
    delay(500);
    Serial.println("CALIBRATING SENSORS...");
    accelXCalibrationValue = accelX();
    accelYCalibrationValue = accelY();
    accelZCalibrationValue = accelZ();
    gyroXCalibrationValue = gyroX();
    gyroYCalibrationValue = gyroY();
    gyroZCalibrationValue = gyroZ();
    noTone(BUZZER1_PORT);
    digitalWrite(G_LED_PORT, LOW);
    Serial.println("ALL SENSORS CALIBRATED");
}

D3 IMU::calibratedAccelData(){
    D3 accelData(accelX() - accelXCalibrationValue, accelZ() - accelZCalibrationValue, -accelY() + accelYCalibrationValue);
    return accelData;
}

D3 IMU::calibratedGyroData(){
    D3 gyroData(gyroX() - gyroXCalibrationValue, gyroZ() - gyroZCalibrationValue, -gyroY() + gyroYCalibrationValue);
    return gyroData;
}

float IMU::getSpeed() {
    return sqrt(accData.X * accData.X + accData.Y * accData.Y + accData.Z * accData.Z) * 9.8;
}

// float IMU::getPitch() { return pitchKalmanFilter.updateEstimate(atan2((-accData.X), sqrt(accData.Y * accData.Y + accData.Z * accData.Z)) * 57.3); }
// float IMU::getRoll() { return atan2(accData.Y, accData.Z) * 57.3; }
// float IMU::getYaw() { return atan(accData.Z / sqrt(accData.X * accData.X + accData.Z * accData.Z)) * 57.3; }

void IMU::updateSensors() {
    accelUpdate();
    gyroUpdate();

    accData = calibratedAccelData();
    gyroData = calibratedGyroData();
    speed = getSpeed();

    // pitch = getPitch();
    // roll = getRoll();
    // yaw = getYaw();
}

void IMU::output()
{
    Serial.println("    ");
    // Serial.println("Accel:");
    // Serial.println(accData.X);
    // Serial.println(accData.Y);
    // Serial.println(accData.Z);
    // Serial.println("Pitch: " + String(getPitch()) + "°");
    // Serial.println("Yaw: " + String(getYaw()) + "°");
    // Serial.println("Roll: " + String(getRoll()) + "°");
    // Serial.println("SPEED " + String(speed) + "m/s");
    // Serial.println("Gyro:");
    // Serial.println(gyroData.X);
    // Serial.println(gyroData.Y);
    // Serial.println(gyroData.Z);

    magUpdate();
    Serial.println("MAG:");
    Serial.println(magX());
    Serial.println(magY());
    Serial.println(magZ());
    Serial.println(magHorizDirection());
}

This is how i have connected my sensor with the arduino board:
image
image

Can someone help?

@asukiaaa
Copy link
Owner

asukiaaa commented Jun 18, 2023

Did you tried example code? (What is IMU.h? Is it orher library?)
https://github.com/asukiaaa/MPU9250_asukiaaa/blob/master/examples/GetData/GetData.ino
If there is problem with the example, the hardware (IC) or circuit may have problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants