Arduino-UNO MPU9250/6500

摘要:
接线MPU9250-->UNOVC->5vGND->GNDSCL->A5SDA->A4I2C地址扫描#包括<金属丝h>voisesetup(){Wire.begin();Serial.beggin(9600);while(!Serial);//Leonardo:waitforserialmonitorSerial.println(“I2CS
接线

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
} 
读取参数

安装库:

Arduino-UNO MPU9250/6500第1张

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

Arduino-UNO MPU9250/6500第2张

#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);
}

免责声明:文章转载自《Arduino-UNO MPU9250/6500》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇COLA 4.0:应用架构的最佳实践Debian-linux 网卡配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

SecureCRT优化调整、永久设置、保护眼睛和配色方案

您可以根据个人喜好调整字体大小。我已经习惯了4号字体。到目前为止,SecureCRT优化已经完成。...

Python-正则

,三:量词*重复0次或多次{0,}+重复一次或多次{1,}?重复0或1次{1,0}{n}重复n次{n}{n,}重复n次,或更多次{n,m}将n次重复到m次Escape:如果字符串中有特殊字符要匹配,请在常规字符和字符串前面添加r。如果特殊字符在字符组中,则它们是匹配的特殊字符,但为了记忆,匹配时会转义所有特殊字符。...

pycharm最新版本激活码(永久有效) python安装教程

输入python以查看当前版本的python。您可以输入“print'helloworld”并单击下载以启动PyCharm://pan.baidu.com//1eVdm4dUPKn3ZY_Xj kqNXw提取代码:l83f2,下载破解补丁(版本2018.3.5)下载链接至地址:...

dBFs和dBm

dBFs和dBmdBFs是用来表征数字域功率值的大小,一般情况下我们定义0dBFs为数字域满刻度功率值,即数字域中功率的最大值;因此看到的dBFs的值都是负的。...

go语言游戏服务端开发(一)——架构

本教程以Go语言为例。特别是游戏服务进程有更新上线时,稳定性还没有被线上并发验证,宕机的几率会增加,数据丢失的风险也会增加。为了减轻风险,可以考虑把数据缓存跟服务进程分离。对于轻中度游戏,游戏的通信量不会很多,没必要每个分服都有一个长连接socket网关。假设一个分服同时连接服务器的客户端有5k,一台机器的socket网关能支持5w个玩家。因此网关需要参与服...