zoukankan      html  css  js  c++  java
  • Arduino-UNO MPU9250/6500

    接线

    MPU9250 --->  UNO

    vcc -> 5v

    GND - > GND

    SCL -> A5

    SDA -> A4

    I2C地址扫描

    #include <Wire.h>
     
     
    void setup()
    {
      Wire.begin();
     
      Serial.begin(9600);
      while (!Serial);             // Leonardo: wait for serial monitor
      Serial.println("I2C Scanner");
    }
     
     
    void loop()
    {
      byte error, address;
      int nDevices;
     
      Serial.println("Scanning...");
     
      nDevices = 0;
      for(address = 1; address < 127; address++ )
      {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
     
        if (error == 0)
        {
          Serial.print("I2C device found at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.print(address,HEX);
          Serial.println("  !");
     
          nDevices++;
        }
        else if (error==4)
        {
          Serial.print("Unknown error at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.println(address,HEX);
        }    
      }
      if (nDevices == 0)
        Serial.println("No I2C devices found");
      else
        Serial.println("done");
     
      delay(5000);           // wait 5 seconds for next scan
    } 

    读取参数

    安装库:

    根据端口扫描结果,设置端口地址:

    #include "MPU9250.h"
    
    // an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
    MPU9250 IMU(Wire,0x68);
    int status;
    
    void setup() {
      // serial to display data
      Serial.begin(115200);
      while(!Serial) {}
    
      // start communication with IMU 
      status = IMU.begin();
      if (status < 0) {
        Serial.println("IMU initialization unsuccessful");
        Serial.println("Check IMU wiring or try cycling power");
        Serial.print("Status: ");
        Serial.println(status);
        while(1) {}
      }
    }
    
    void loop() {
      // read the sensor
      IMU.readSensor();
      // display the data
    
      //加速度
      Serial.print(IMU.getAccelX_mss(),6);
      Serial.print("	");
      Serial.print(IMU.getAccelY_mss(),6);
      Serial.print("	");
      Serial.print(IMU.getAccelZ_mss(),6);
      Serial.print("	");
    
      //陀螺仪
      Serial.print(IMU.getGyroX_rads(),6);
      Serial.print("	");
      Serial.print(IMU.getGyroY_rads(),6);
      Serial.print("	");
      Serial.print(IMU.getGyroZ_rads(),6);
      Serial.print("	");
    
      //磁力计
      Serial.print(IMU.getMagX_uT(),6);
      Serial.print("	");
      Serial.print(IMU.getMagY_uT(),6);
      Serial.print("	");
      Serial.print(IMU.getMagZ_uT(),6);
      Serial.print("	");
      Serial.println(IMU.getTemperature_C(),6);
      delay(100);
    }
  • 相关阅读:
    接口的经典使用方法
    多态的程序例子
    log4j常用配置过程
    log4j.properties对于web app摆放的位置
    MySQL优化实例
    No sql 相关
    yii直接执行sql
    android NDK JNI设置自己的log输出函数
    android web 网址收集
    WebKit加载网页的流程
  • 原文地址:https://www.cnblogs.com/Archger/p/12774659.html
Copyright © 2011-2022 走看看