MPU6050のサンプルプログラム2
Dependencies: ConfigFile SDFileSystem mbed
Fork of LAURUS_program by
Diff: MPU6050/MPU6050.cpp
- Revision:
- 1:6cd6d2760856
- Parent:
- 0:bc6f14fc60c7
--- a/MPU6050/MPU6050.cpp Fri May 15 17:24:32 2015 +0000 +++ b/MPU6050/MPU6050.cpp Sun May 24 17:32:47 2015 +0000 @@ -1,8 +1,7 @@ #include "mbed.h" #include "MPU6050.h" -MPU6050::MPU6050(I2C* i2c) { - this->i2c = i2c; +MPU6050::MPU6050(I2C* p_i2c): i2c(p_i2c){ } MPU6050::~MPU6050() { @@ -10,10 +9,21 @@ } int MPU6050::init() { + // スリープモード解除 char cmd[2] = {0x6b, 0x00}; int ret = i2c->write(mpu_addr, cmd, 2); + if(ret != 0) return 0; + // ジャイロのレンジを500deg/sに設定 + char data = 0; + cmd[0] = 0x1b; + ret = i2c->write(mpu_addr, cmd, 1, true); if(ret != 0) return 0; + i2c->read(mpu_addr | 0x01, &data, 1, false); + cmd[1] = data | 0x08; + ret = i2c->write(mpu_addr, cmd, 2); + if(ret != 0) return 0; + return 1; }