获取姿态传感器三轴角度

来自Microduino Wikipedia
1196357542@qq.com讨论 | 贡献2018年11月16日 (五) 05:30的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

描述

在下面的示例中,使用mCenter+检测姿态传感器的三轴角度,通过串口将数值打印出来

所需硬件


电路搭建

将姿态传感器接到mCenter+的I2C引脚。
将mCenter+通过MicroUSB数据线接入电脑,板卡选择"Core+ 5V"。初次使用请参考:Getting Started

代码

单独读取各轴角度

#include <Microduino_sensorMotion.h>

sensorMotion mpu6050;

void setup()
{
  //串口初始化
  Serial.begin(115200);
  mpu6050.begin();
}

void loop()
{
  Serial.print(mpu6050.getYaw());
  Serial.print(" \t");
  Serial.print(mpu6050.getPitch());
  Serial.print(" \t");
  Serial.print(mpu6050.getRoll());
  Serial.println(" ");

  delay(10);
}


快速读取三轴角度

#include <Microduino_sensorMotion.h>

sensorMotion mpu6050;

float ypr[3];

void setup()
{
  //串口初始化
  Serial.begin(115200);
  mpu6050.begin();
}

void loop()
{
  mpu6050.getYawPitchRoll(ypr);
  Serial.print("ypr\t");
  Serial.print(ypr[0]);
  Serial.print("\t");
  Serial.print(ypr[1]);
  Serial.print("\t");
  Serial.println(ypr[2]);

  delay(10);
}




返回Sensor-Motion界面

返回Sensor-Motion_Reference界面