The equipment used

In this paper, an Arduino Uno development board is used to connect the MPU9250 sensor, and the sensor acceleration and gyroscope data are obtained.

  • Arduino Uno

  • MPU9250

  • Wired way
MPU9250 Arduino
3.3 V VCC
GND GND
A4 SDA
A5 SCL

preparation

  • Download the MPU9250 library

Write code to get attitude angles (Roll, Yaw, Pitch)

#include "MPU9250.h"

MPU9250 mpu;

void setup(a) {
    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); }}}void loop(a) {
    if (mpu.update()) {
        static uint32_t prev_ms = millis();
        if (millis() > prev_ms + 25) { print_roll_pitch_yaw(); prev_ms = millis(); }}}void print_roll_pitch_yaw(a) {
    Serial.print("Yaw, Pitch, Roll: ");
    Serial.print(mpu.getYaw(), 2);
    Serial.print(",");
    Serial.print(mpu.getPitch(), 2);
    Serial.print(",");
    Serial.println(mpu.getRoll(), 2);
}
Copy the code

A serial port output