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

Dependencies:   mbed MPU6050

main.cpp

Committer:
ritarosakai
Date:
2018-01-07
Revision:
1:01af59327884
Parent:
0:5efae55d7fbb
Child:
2:6e9393d9cc11

File content as of revision 1:01af59327884:

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

MPU6050 mpu(D7,D8);//for Nucleo-F042K6
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);
    }
}