MPU6050センサ Wallbot_BLE用 サンプル
Dependencies: BLE_API mbed nRF51822
Revision 22:05d9fca84f59, committed 2018-06-03
- Comitter:
- Dyotty
- Date:
- Sun Jun 03 07:00:30 2018 +0000
- Parent:
- 21:600cf473d9e7
- Commit message:
- First commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 600cf473d9e7 -r 05d9fca84f59 main.cpp --- a/main.cpp Sat Jun 27 13:26:34 2015 +0000 +++ b/main.cpp Sun Jun 03 07:00:30 2018 +0000 @@ -24,9 +24,18 @@ BLE ble; -MPU6050 mpu(I2C_SDA0, I2C_SCL0); +///// 180601 +/********* 変数宣言 ***********/ + +// MPU6050 G & Gyroセンサ 変数宣言 +MPU6050 mpu(I2C_SDA, I2C_SCL); -static const char DEVICENAME[] = "BLE-Nano"; +// Serial通信 変数宣言 +Serial pc(USBTX, USBRX); +///// 180601 + + +static const char DEVICENAME[] = "WallbotBLE"; static volatile bool triggerSensorPolling = false; //const uint8_t MPU6050_adv_service_uuid[] = { @@ -68,23 +77,27 @@ GattService MPU6050Service(MPU6050_service_uuid, ControllerChars, sizeof(ControllerChars) / sizeof(GattCharacteristic *)); - +///// 180601 +// ・MPU6050から値を取得 +// ・ループ実行されている関数 void updateValue(void){ + // 値を格納する用の配列、変数 float acData[3]; float gyData[3]; float tempData = 0.0f; float at = 0.0f; float gt = 0.0f; float tickerInterval = 0.0f; - + //加速度を取得 Timer acTimer; acTimer.start(); - mpu.getAccelero(acData); + mpu.getAccelero(acData); //加速度を取得 acDataに格納 acTimer.stop(); at = acTimer.read_ms(); acTimer.reset(); + //BLEで送信されるデータメモリに値をコピー(ここは今回使わない) memcpy(accelPayload+sizeof(float)*0, &acData[0], sizeof(acData[0])); memcpy(accelPayload+sizeof(float)*1, &acData[1], sizeof(acData[1])); memcpy(accelPayload+sizeof(float)*2, &acData[2], sizeof(acData[2])); @@ -92,15 +105,19 @@ //ジャイロを取得 Timer gyTimer; gyTimer.start(); - mpu.getGyro(gyData); + mpu.getGyro(gyData); //ジャイロの値(角加速度)を取得 gyDataに格納 gyTimer.stop(); gt = gyTimer.read_ms(); gyTimer.reset(); - + + //BLEで送信されるデータメモリに値をコピー(ここは今回使わない) memcpy(accelPayload+sizeof(float)*3, &gyData[0], sizeof(gyData[0])); memcpy(accelPayload+sizeof(float)*4, &gyData[1], sizeof(gyData[1])); memcpy(accelPayload+sizeof(float)*5, &gyData[2], sizeof(gyData[2])); + //floatの値を合計5桁、小数点以下3桁の形でPCへ送信 + pc.printf("%5.3f:%5.3f:%5.3f:%5.3f:%5.3f:%5.3f \n", acData[0], acData[1], acData[2],gyData[0],gyData[1],gyData[2]); + //温度を取得 tempData = mpu.getTemp(); @@ -257,9 +274,12 @@ #define MPU6050_GYRO_RANGE_2000 4 */ + + ///180601 MPU6050センサの初期化処理 mpu.initialize(); - mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_8G); - mpu.setGyroRange(MPU6050_GYRO_RANGE_1000); + mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_8G); //加速度センサ 計測レンジ設定(今回は2Gか4Gがよさそう) + mpu.setGyroRange(MPU6050_GYRO_RANGE_1000); //ジャイロセンサ 計測レンジ設定(ここも250か500がよさそう(そんなに早く回転しないので)) + ///180601 if( mpu.testConnection() ){ //pc.printf("mpu test:OK\n\r"); @@ -293,13 +313,17 @@ ble.addService(MPU6050Service); + + pc.printf("Start!! \n"); + while(true) { - if (triggerSensorPolling && ble.getGapState().connected) { - triggerSensorPolling = false; +// if (triggerSensorPolling && ble.getGapState().connected) { +// triggerSensorPolling = false; updateValue(); - } else { - ble.waitForEvent(); - } + wait(0.5); +// } else { +// ble.waitForEvent(); +// } } }