the lastest code by Castle. 27 Nov
Dependencies: mpu9250_i2c biquadFilter PCA peakdetection Eigen
Diff: main.cpp
- Revision:
- 0:44701eab0261
- Child:
- 1:92f42e198925
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 06 12:36:55 2019 +0000 @@ -0,0 +1,46 @@ +/* + * reading and print acc and gyro date from MPU9250 + * in terminal: + * ls /dev/tty.* + * screen /dev/tty.usbmodem14102 9600 + * + * mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mbed.h" +#include "platform/mbed_thread.h" +#include "stats_report.h" +#include "MPU9250.h" + +DigitalOut led1(LED1); +const int addr7bit = 0x68; // 7bit I2C address,AD0 is 0 + +#define SLEEP_TIME 1000 // (msec) + +// main() runs in its own thread in the OS +int main() +{ + //new mpu(data,clk,address),in constructor addr7bit<<1 + mpu9250 *mpu = new mpu9250(p26,p27,addr7bit); + //scale of acc and gyro + mpu->initMPU9250(0x00,0x00); + + float AccRead[3]; + float GyroRead[3]; + float TempRead[1]; + + while (true) { + + //Blink LED and wait 1 seconds + led1 = !led1; + thread_sleep_for(SLEEP_TIME); + //read and convert date + mpu->ReadConvertAll(AccRead,GyroRead,TempRead); + printf("acc value is (%f,%f,%f).\n\r",AccRead[0],AccRead[1],AccRead[2]); + printf("gyro value is (%f,%f,%f).\n\r",GyroRead[0],GyroRead[1],GyroRead[2]); + printf("temp value is %f.\n\r",TempRead[0]); + + } +}