본문 바로가기

RaspberryPi/RP2040

RP2040 - I2C MPU9250 IMU 테스트

 

RP2040을 이용하여 9축 IMU MPU9250 모듈을 테스트 해보자.

MPU9250은 I2C()에 연결되어 있다.

 

 

MPU9250 라이브러리는 하기 링크로 다운받아 테스트 했다

GitHub - bolderflight/mpu9250: Arduino and CMake library for communicating with the InvenSense MPU-9250 and MPU-9255 nine-axis IMUs.

 

GitHub - bolderflight/mpu9250: Arduino and CMake library for communicating with the InvenSense MPU-9250 and MPU-9255 nine-axis I

Arduino and CMake library for communicating with the InvenSense MPU-9250 and MPU-9255 nine-axis IMUs. - GitHub - bolderflight/mpu9250: Arduino and CMake library for communicating with the InvenSens...

github.com

 

 

 

 

기본 예제를 수정해서 로데이터를 출력하도록 해 보았다.

#include "MPU9250.h"

MPU9250 mpu;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    delay(2000);
    
    if (!mpu.setup(0x68)) {  // change to your own address
        while (1) {
            Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
            delay(5000);
        }
    }

    //print_calibration();
    mpu.verbose(false);
}

void loop() {
    if (mpu.update()) {
        static uint32_t prev_ms = millis();
        if (millis() > prev_ms + 25) {
            
            print_rawdata();
            
            //print_roll_pitch_yaw();
            prev_ms = millis();
        }
    }
}

void print_roll_pitch_yaw() {
    //Serial.print("Yaw, Pitch, Roll: ");
    Serial.print(mpu.getYaw(), 2);
    Serial.print(", ");
    Serial.print(mpu.getPitch(), 2);
    Serial.print(", ");
    Serial.println(mpu.getRoll(), 2);
}

void print_rawdata() {
    Serial.print(mpu.getAccX());
    Serial.print(", ");
    Serial.print(mpu.getAccY());
    Serial.print(", ");
    Serial.print(mpu.getAccZ());
    Serial.print(", ");

	Serial.print(mpu.getGyroX());
    Serial.print(", ");
    Serial.print(mpu.getGyroY());
    Serial.print(", ");
    Serial.print(mpu.getGyroZ());
    Serial.print(", ");

    Serial.print(mpu.getMagX());
    Serial.print(", ");
    Serial.print(mpu.getMagY());
    Serial.print(", ");
    Serial.print(mpu.getMagZ());
    Serial.print(", ");

    Serial.print(mpu.getMagScaleX());
    Serial.print(", ");
    Serial.print(mpu.getMagScaleY());
    Serial.print(", ");
    Serial.print(mpu.getMagScaleZ());
    Serial.println("");
}

 

 

MPU9250 IMU 테스트 결과

반응형