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

Dependencies:   mbed MPU6050

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MPU6050.h"
00003 
00004 MPU6050 mpu(D4,D5);
00005 Serial pc(USBTX,USBRX);
00006 
00007 float gx,gy,gz,ax,ay,az;
00008 
00009 int main()
00010 {
00011     pc.baud(115200);
00012     if(mpu.getID()==0x68) {
00013         pc.printf("MPU6050 OK");
00014         wait(1);
00015     } else {
00016         pc.printf("MPU6050 error ID=0x%x\r\n",mpu.getID());
00017         while(1) {
00018         }
00019     }
00020     mpu.start();
00021     while(1) {
00022         mpu.read(&gx,&gy,&gz,&ax,&ay,&az);
00023         pc.printf("gx,gy,gz,ax,ay,az %.1f,%.1f,%.1f,%.2f,%.2f,%.2f\r\n",gx,gy,gz,ax,ay,az);
00024         wait(0.1);
00025     }
00026 }