I2C通信を使用した角速度測定、LCD表示サンプル

Dependencies:   mbed mbed_mpu6050_i2c_raw_register AQM0802

Committer:
yusaku0125
Date:
Fri Jul 19 10:37:29 2019 +0000
Revision:
4:bf507fe18cb2
Parent:
3:ebd656a9c89f
Child:
5:8c482bdfb9e8
gyro_lcd_disp_test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
satoshi1204 0:abd3a0fd55a9 1 #include "mbed.h"
yusaku0125 4:bf507fe18cb2 2 #include "AQM0802.h"
satoshi1204 0:abd3a0fd55a9 3 #include "mpu6050.h"
satoshi1204 0:abd3a0fd55a9 4
satoshi1204 0:abd3a0fd55a9 5 Serial pc(USBTX, USBRX);
yusaku0125 4:bf507fe18cb2 6 MPU6050 mpu(D4, D5);
yusaku0125 4:bf507fe18cb2 7 AQM0802 lcd(I2C_SDA,I2C_SCL);
satoshi1204 0:abd3a0fd55a9 8
satoshi1204 0:abd3a0fd55a9 9 int main() {
yusaku0125 4:bf507fe18cb2 10 double gx,gy,gz; //Z角速度情報を格納
yusaku0125 4:bf507fe18cb2 11 int i_gz;
yusaku0125 4:bf507fe18cb2 12 char str[5];
yusaku0125 4:bf507fe18cb2 13 pc.baud(9600);
yusaku0125 4:bf507fe18cb2 14 mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec);//[1000deg/sec]を測定上限とする。
yusaku0125 4:bf507fe18cb2 15 lcd.init();
yusaku0125 4:bf507fe18cb2 16 lcd.locate(1,0);//桁、行
yusaku0125 4:bf507fe18cb2 17 lcd.print("GYRO_Z");//1行目に「GYRO_Z」を表示
satoshi1204 3:ebd656a9c89f 18 while(true) {
yusaku0125 4:bf507fe18cb2 19 mpu.readGyroscope(gx, gy, gz);//関数仕様上3軸すべて角速度取得する。
yusaku0125 4:bf507fe18cb2 20 i_gz=(int)gz;//doubleは大きすぎるのでint型へ変換
yusaku0125 4:bf507fe18cb2 21 pc.printf("gz:%d\r\n", i_gz);//Z軸方向のみ表示する。(他は使わない)
yusaku0125 4:bf507fe18cb2 22 lcd.locate(1,1);//桁、行
yusaku0125 4:bf507fe18cb2 23 lcd.print(" ");//表示クリア
yusaku0125 4:bf507fe18cb2 24 sprintf(str,"%4d",i_gz);
yusaku0125 4:bf507fe18cb2 25 lcd.locate(1,1);//桁、行
yusaku0125 4:bf507fe18cb2 26 lcd.print(str);//表示クリア
satoshi1204 0:abd3a0fd55a9 27 wait(0.2);
satoshi1204 0:abd3a0fd55a9 28 }
satoshi1204 0:abd3a0fd55a9 29 }