Hello all!
I am using a BMI160 to detect the heeling angle of a sailboat. I need to know the current angle of the sensor at all times to do this.
I have wired and coded a setup that works just fine, but... I cant figure out how to know my current angle in degrees! How would I do this? And I don't understand what the BMI160 is outputting for information; like unit of measurement or something.
Thanks in advance!
Code:
/*!
* @file accelGyro.ino
* @brief I2C addr:
* @n 0x68: connect SDIO pin of the BMI160 to GND which means the default I2C address
* @n 0x69: set I2C address by parameter
* @n Through the example, you can get the sensor data by using getSensorData:
* @n get acell by paremeter onlyAccel;
* @n get gyro by paremeter onlyGyro;
* @n get both acell and gyro by paremeter bothAccelGyro.
* @n With the rotation of the sensor, data changes are visible.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author DFRobot_haoJ(hao.jiang@dfrobot.com)
* @version V1.0
* @date 2017-12-01
* @url https://github.com/DFRobot/DFRobot_BMI160
*/
#include <DFRobot_BMI160.h>
float xcurrentpos;
float ycurrentpos;
float zcurrentpos;
DFRobot_BMI160 bmi160;
const int8_t i2c_addr = 0x69;
void setup(){
Serial.begin(115200);
delay(100);
//init the hardware bmin160
if (bmi160.softReset() != BMI160_OK){
Serial.println("reset false");
while(1);
}
//set and init the bmi160 i2c address
if (bmi160.I2cInit(i2c_addr) != BMI160_OK){
Serial.println("init false");
while(1);
}
}
void loop(){
int i = 0;
int rslt;
//int16_t accelGyro[6]={0};
////only read gyro data from bmi160
int16_t onlyGyro[3]={0};
rslt = bmi160.getGyroData(onlyGyro);
//get both accel and gyro data from bmi160
//parameter accelGyro is the pointer to store the data
//rslt = bmi160.getAccelGyroData(accelGyro);
if(rslt == 0){
xcurrentpos = xcurrentpos += (onlyGyro[0]*3.14/180.0);
ycurrentpos = ycurrentpos += (onlyGyro[1]*3.14/180.0);
zcurrentpos = zcurrentpos += (onlyGyro[2]*3.14/180.0);
Serial.print("X: " + String(onlyGyro[0]*3.14/180.0));
Serial.print(" Y: " + String(onlyGyro[1]*3.14/180.0));
Serial.print(" Z: " + String(onlyGyro[2]*3.14/180.0));
Serial.print(" XC: " + String(xcurrentpos));
Serial.print(" YC: " + String(ycurrentpos));
Serial.println(" ZC: " + String(zcurrentpos));
/*
for(i=0;i<3;i++){
//if (i<3){
//the first three are gyro data
Serial.print(onlyGyro[i]*3.14/180.0);Serial.print("\t");
//}
//else{
//the following three data are accel data
// Serial.print(onlyGyro[i]/16384.0);Serial.print("\t");
//}
}
Serial.println();
}else{
Serial.println("err");*/
}
delay(100);
/*
* //only read accel data from bmi160
* int16_t onlyAccel[3]={0};
* bmi160.getAccelData(onlyAccel);
*/
}