sparkfun / SparkFun_BNO080_Arduino_Library

An Arduino Library for the BNO080 IMU combination triple axis accelerometer/gyro/magnetometer packaged with an ARM Cortex M0+ running powerful algorithms.
Other
81 stars 62 forks source link

Questions when using two sensors #21

Closed besabestin closed 5 years ago

besabestin commented 5 years ago

I have two questions when I am using data from two sensors. I have not programmed on a very low level, so please bear with me. The first is about the data I am getting. Not always, but sometimes I am receiving data that looks like the following.

issue_plot

The x-axis is the sample number. After about the 200th sample Both the accelerometer and gyroscope data starting fixing on some value for a long time. Based on the movements I did it shouldn't be like this. I didn't do anything different after sample number 200 that I didn't do before sample 200. I am curious on what type of situations does this happen? There is also a similar closed issue.

I am using the following code that is almost copied from the examples.

//a highly minimized code.

#include <Wire.h>
#include <SparkFun_BNO080_Arduino_Library.h>

BNO080 myIMU1; //Open I2C ADR jumper - goes to address 0x4B
BNO080 myIMU2; //Closed I2C ADR jumper - goes to address 0x4A

unsigned long previousStamp1, previousStamp2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Finish reading the arduino data");

  Wire.begin();
  Wire.setClock(400000); //Increase I2C data rate to 400kHz

  if (myIMU1.begin() == false)
  {
    Serial.println("First BNO080 not detected with I2C ADR jumper open. Check your jumpers and the hookup guide. Freezing...");
    while(1);
  }

  if (myIMU2.begin() == false)
  {
    Serial.println("Second BNO080 not detected with I2C ADR jumper closed. Check your jumpers and the hookup guide. Freezing...");
    while(1);
  }

  myIMU1.enableGyro(100);
  myIMU2.enableAccelerometer(100);

  previousStamp1 = micros();
  previousStamp2 = micros();
}

void loop() {

  unsigned long currStamp1 = micros();
  unsigned long diffStamp1 = currStamp1 - previousStamp1;

  unsigned long currStamp2 = micros();
  unsigned long diffStamp2 = currStamp2 - previousStamp2;

  if(diffStamp1 > 100000 && myIMU1.dataAvailable() == true){
    previousStamp1 = currStamp1;
    outputGyro();
  }

  if(diffStamp2 > 100000 && myIMU2.dataAvailable() == true){
    previousStamp2 = currStamp2;
    outputAccelerometer();
  }

}

void outputGyro(){

    float x = myIMU1.getGyroX();
    float y = myIMU1.getGyroY();
    float z = myIMU1.getGyroZ();

    Serial.print("4");
    Serial.print(" ");
    Serial.print(x, 4);
    Serial.print(" ");
    Serial.print(y, 4);
    Serial.print(" ");
    Serial.print(z, 4);
    Serial.print(" ");
    Serial.print(previousStamp1);
    Serial.println();

}

void outputAccelerometer(){

    float x = myIMU2.getAccelX();
    float y = myIMU2.getAccelY();
    float z = myIMU2.getAccelZ();

    Serial.print("1");
    Serial.print(" ");
    Serial.print(x, 4);
    Serial.print(" ");
    Serial.print(y, 4);
    Serial.print(" ");
    Serial.print(z, 4);
    Serial.print(" ");
    Serial.print(previousStamp2);
    Serial.println();

}

The other question I have is that you are using something like myIMU1.begin(0x4B) and where do I get the addresses from?

I appreciate the support. thanks.

besabestin commented 5 years ago

I had an idea that two sensors in your examples was about the sensors in an IMU, while it is about multiple IMUs. My bad. So my issue is gone now. I close this issue.