Program for testing development of BMI160 Library
Dependencies: BMI160 max32630fthr mbed
Diff: main.cpp
- Revision:
- 4:3d7fae7f7b75
- Parent:
- 3:250503cb7cb3
- Child:
- 5:4deb38e46a10
--- a/main.cpp Tue Dec 20 01:30:12 2016 +0000 +++ b/main.cpp Tue Dec 20 23:59:35 2016 +0000 @@ -49,7 +49,7 @@ DigitalOut rLED(LED1, LED_OFF); DigitalOut gLED(LED2, LED_OFF); - DigitalOut bLED(LED3, LED_ON); + DigitalOut bLED(LED3, LED_OFF); I2C i2cBus(P5_7, P6_0); i2cBus.frequency(400000); @@ -60,23 +60,95 @@ imu.setSensorPowerMode(BMI160::ACC, BMI160::NORMAL); wait_ms(100); - float imuTemperature, sensorTime; - BMI160::SensorData accData; - //BMI160::SensorData gyroData; + uint32_t failures = 0; + + printf("\033[H"); //home + printf("\033[0J"); //erase from cursor to end of screen + + BMI160::AccConfig accConfig; + //example of using getSensorConfig + if(imu.getSensorConfig(accConfig) == BMI160::RTN_NO_ERROR) + { + printf("ACC Range = %d\n", accConfig.range); + printf("ACC UnderSampling = %d\n", accConfig.us); + printf("ACC BandWidthParam = %d\n", accConfig.bwp); + printf("ACC OutputDataRate = %d\n\n", accConfig.odr); + } + else + { + printf("Failed to get accelerometer configuration\n"); + failures++; + } - while(1) + //example of setting user defined configuration + accConfig.range = BMI160::SENS_4G; + accConfig.us = BMI160::ACC_US_OFF; + accConfig.bwp = BMI160::ACC_BWP_2; + accConfig.odr = BMI160::ACC_ODR_8; + if(imu.setSensorConfig(accConfig) == BMI160::RTN_NO_ERROR) + { + printf("ACC Range = %d\n", accConfig.range); + printf("ACC UnderSampling = %d\n", accConfig.us); + printf("ACC BandWidthParam = %d\n", accConfig.bwp); + printf("ACC OutputDataRate = %d\n\n", accConfig.odr); + } + else + { + printf("Failed to set accelerometer configuration\n"); + failures++; + } + + BMI160::GyroConfig gyroConfig; + if(imu.getSensorConfig(gyroConfig) == BMI160::RTN_NO_ERROR) { - imu.getAccXYZ(accData, BMI160::DEFAULT_ACC_CONFIG); - imu.getSensorTime(&sensorTime); - imu.getTemperature(&imuTemperature); - + printf("GYRO Range = %d\n", gyroConfig.range); + printf("GYRO BandWidthParam = %d\n", gyroConfig.bwp); + printf("GYRO OutputDataRate = %d\n\n", gyroConfig.odr); + } + else + { + printf("Failed to get gyroscope configuration\n"); + failures++; + } + + wait(5.0); + printf("\033[H"); //home + printf("\033[0J"); //erase from cursor to end of screen + + if(failures == 0) + { + float imuTemperature; + BMI160::SensorData accData; + BMI160::SensorData gyroData; + BMI160::SensorTime sensorTime; - printf("ACC xAxis = %s%4.3f\n", "\033[K", accData.xAxis.scaled); - printf("ACC yAxis = %s%4.3f\n", "\033[K", accData.yAxis.scaled); - printf("ACC zAxis = %s%4.3f\n", "\033[K", accData.zAxis.scaled); - printf("Sensor Time = %s%f\n", "\033[K", sensorTime); - printf("Sensor Temperature = %s%5.3f\n", "\033[K", imuTemperature); - printf("\033[H"); //home + while(1) + { + imu.getGyroAccXYZandSensorTime(accData, gyroData, sensorTime, accConfig.range, gyroConfig.range); + imu.getTemperature(&imuTemperature); + + printf("ACC xAxis = %s%4.3f\n", "\033[K", accData.xAxis.scaled); + printf("ACC yAxis = %s%4.3f\n", "\033[K", accData.yAxis.scaled); + printf("ACC zAxis = %s%4.3f\n\n", "\033[K", accData.zAxis.scaled); + + printf("GYRO xAxis = %s%5.1f\n", "\033[K", gyroData.xAxis.scaled); + printf("GYRO yAxis = %s%5.1f\n", "\033[K", gyroData.yAxis.scaled); + printf("GYRO zAxis = %s%5.1f\n\n", "\033[K", gyroData.zAxis.scaled); + + printf("Sensor Time = %s%f\n", "\033[K", sensorTime.seconds); + printf("Sensor Temperature = %s%5.3f\n", "\033[K", imuTemperature); + + printf("\033[H"); //home + gLED = !gLED; + } + } + else + { + while(1) + { + rLED = !rLED; + wait(0.25); + } } }