获取mpu6050 六轴传感器数据,从打印串口中输出

Dependencies:   mbed MPU6050

main.cpp

Committer:
ritarosakai
Date:
2019-08-15
Revision:
2:6e9393d9cc11
Parent:
1:01af59327884

File content as of revision 2:6e9393d9cc11:

#include "mbed.h"
#include "MPU6050.h"

MPU6050 mpu(D4,D5);
Serial pc(USBTX,USBRX);

float gx,gy,gz,ax,ay,az;

int main()
{
    pc.baud(115200);
    if(mpu.getID()==0x68) {
        pc.printf("MPU6050 OK");
        wait(1);
    } else {
        pc.printf("MPU6050 error ID=0x%x\r\n",mpu.getID());
        while(1) {
        }
    }
    mpu.start();
    while(1) {
        mpu.read(&gx,&gy,&gz,&ax,&ay,&az);
        pc.printf("gx,gy,gz,ax,ay,az %.1f,%.1f,%.1f,%.2f,%.2f,%.2f\r\n",gx,gy,gz,ax,ay,az);
        wait(0.1);
    }
}