MPU-6050 sample code

Dependencies:   mbed

Dependents:   i2c_gyro_disp

Files at this revision

API Documentation at this revision

Comitter:
satoshi1204
Date:
Thu Dec 13 15:35:41 2018 +0000
Parent:
2:f2db52a742b0
Commit message:
fix register address.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mpu6050.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f2db52a742b0 -r ebd656a9c89f main.cpp
--- a/main.cpp	Thu Dec 13 03:07:35 2018 +0000
+++ b/main.cpp	Thu Dec 13 15:35:41 2018 +0000
@@ -8,7 +8,7 @@
 DigitalOut led4(LED4);
 MPU6050 mpu(p9, p10);
 
-void allTurnOffLed()
+void turnOffAllLed()
 {
     led1 = 0;
     led2 = 0;
@@ -23,7 +23,7 @@
     double gx, gy, gz;
     mpu.readGyroscope(gx, gy, gz);
     pc.printf("%.4lf %.4lf %.4lf %.4lf %.4lf %.4lf\r\n", ax, ay, az, gx, gy, gz);
-    allTurnOffLed();
+    turnOffAllLed();
     if(ax > ay && ax > az) {
         led1 = 1;
     } else if(ay > ax && ay > az) {
@@ -36,8 +36,9 @@
 }
 
 int main() {
+    pc.baud(115200);
     mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec);
-    while(1) {
+    while(true) {
         readData();
         wait(0.2);
     }
diff -r f2db52a742b0 -r ebd656a9c89f mpu6050.cpp
--- a/mpu6050.cpp	Thu Dec 13 03:07:35 2018 +0000
+++ b/mpu6050.cpp	Thu Dec 13 15:35:41 2018 +0000
@@ -14,7 +14,7 @@
     16.4,
 };
 
-MPU6050::MPU6050(PinName i2c_sda, PinName i2c_scl) : i2c(i2c_sda, i2c_scl), address(0x68 << 1), rate_accelemeter(16384.0), rate_gyroscope(131.0)
+MPU6050::MPU6050(PinName i2c_sda, PinName i2c_scl) : i2c(i2c_sda, i2c_scl), address(0x68 << 1), rate_accelemeter(RATE_ACC_LIST[0]), rate_gyroscope(RATE_GYRO_LIST[0])
 {
     setSleep(false);
     setMaxScale(MAX_ACC_2G, MAX_GYRO_250degpersec);
@@ -55,7 +55,7 @@
     short x, y, z;
     // read X
     h = readByte(0x3B);
-    l = readByte(0x75);
+    l = readByte(0x3C);
     x = h << 8 | l;
     // read Y
     h = readByte(0x3D);