SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Movement & IMU category should be posted in this forum.
#206860
Hey, as I said, Serial.print prints the data of the accelerometer with the previous data from the gyro. Then its prints the previous data from the accel with the current data from the gyro.

Here's the function:

if (myIMU.dataAvailable()) {
float a_x = myIMU.getLinAccelX();
float a_y = myIMU.getLinAccelY();
float a_z = myIMU.getLinAccelZ();
float a_accy = myIMU.getLinAccelAccuracy();
float beta = myIMU.getGyroZ();
float beta_accy = myIMU.getGyroAccuracy();
Serial.print(a_x, 2); //0
Serial.print(F("^"));
Serial.print(a_y, 2); //1
Serial.print(F("^"));
Serial.print(a_z, 2); //2
Serial.print(F("^"));
Serial.print(a_accy, 3); //3
Serial.print(F("^"));
Serial.print(beta, 2); //4
Serial.print(F("^"));
Serial.print(beta_accy, 2); //5
Serial.println();
//delay(16);
}

Here is an example of the data.

-1.68^1.04^-3.46^3.000^-2.34^0.00
-1.68^1.04^-3.46^3.000^-3.89^0.00
0.11^0.14^-1.44^3.000^-3.89^0.00
0.11^0.14^-1.44^3.000^-2.20^0.00
0.27^-6.89^1.24^3.000^-2.20^0.00
0.27^-6.89^1.24^3.000^2.07^0.00
2.52^-3.25^2.48^3.000^2.07^0.00
2.52^-3.25^2.48^3.000^1.60^0.00

It does this at any frequency (1hz, 10 hz, 90 hz) and even if i add delay between each cycle(loop).

How can I make it so the gyro and accelerometer are synced and I dont get 2 prints from serial? (rootcause please, not just a side code to cope with the problem..!)

Thanks.

-Jm
#206885
Hey Chris, thanks for the quick reply.

The code is coming from Arduino Uno R3 and the main structure and code are taken from the examples. The one thing I added is that i enable both gyro and accelerometer at 60 hz (each 16 ms) and in the myImu.dataAvailable, I get data from both as floats.

I am using the VR IMU Breakouthttps://www.sparkfun.com/products/14686.

I can post my code but the IMU is like 1/3 of the code or less. If you need it I can clean it and post it all.

-Jm
#206894
Hi Jm.

I'm afraid we're not able to assist with custom code, but I wonder if there is either an error somewhere in the library or possibly the values that double print are not updating quickly enough and the code is printing old data on the double print.

Nobody else has reported an issue like this so far so I'm not sure it's a library issue. You might try putting a larger delay in your loop to see if that clears this up.
#206914
I have tried with this code. I literally just took linearacceleromter example and put in the code lines from the gyro too to have both inputs.

With delay below to the sensor's enabled frequency or without delay, it still does the same. If the delay is equal or higher than the sensor's enabled frequency, the gyro always comes up with refreshed data and the accelerometer doesn't follow. I can have 5-10 serial prints with the same data for the accelerometer.

I have tried speeding up the accelerometer inputs (using enable) and it always performs weirdly.

It seems the librairy can't manage gyro and accelerometer at the same time, or in the same loop. It seems to have something to do with the librairy and the time it takes to treat the data of the gyro VS accelerometer.

Do you have a code or someone that has a code that works with both accelerometer and gyroscope data? I mean has anyone got it working with both at the same time?

Also, what is this comment in the code? (*Use the interrupt pin on the BNO080 breakout to avoid polling.)

I am using the I2C connection and I used pull-ups as indicated for the data lines.

Thanks.

-Jm
Code: Select all

#include <Wire.h>

#include "SparkFun_BNO080_Arduino_Library.h"
BNO080 myIMU;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  myIMU.begin();

  Wire.setClock(400000); //Increase I2C data rate to 400kHz
  
  myIMU.enableLinearAccelerometer(50); //Send data update every 50ms
  myIMU.enableGyro(50); //Send data update every 50ms

}

void loop()
{
  //Look for reports from the IMU
  if (myIMU.dataAvailable() == true)
  {
    float gx = myIMU.getGyroX();
    float gy = myIMU.getGyroY();
    float gz = myIMU.getGyroZ();
    float x = myIMU.getLinAccelX();
    float y = myIMU.getLinAccelY();
    float z = myIMU.getLinAccelZ();
    Serial.print(gx, 2);
    Serial.print(F(","));
    Serial.print(gy, 2);
    Serial.print(F(","));
    Serial.print(gz, 2);
    Serial.print(F(","));
    Serial.print(x, 2);
    Serial.print(F(","));
    Serial.print(y, 2);
    Serial.print(F(","));
    Serial.print(z, 2);
    Serial.println();
  }
  delay(100);
}