BNO055 Sensor Zeroing All Values

Wearable electronics: boards, conductive materials, and projects from Adafruit!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Jake_CSU
 
Posts: 4
Joined: Tue Nov 15, 2022 1:39 pm

BNO055 Sensor Zeroing All Values

Post by Jake_CSU »

Hello,

I am using two BNO055 sensors, and I just want to get the raw data from the accelerometer and gyroscope for my project. Randomly, one or both of the senors will suddenly start to display all zeros (see image below).
Zeroed Output.PNG
Zeroed Output.PNG (45.31 KiB) Viewed 216 times
I am assuming this is occuring because the device is put into suspension mode, but I do not know what would cause this. My code is below for reference.

Code: Select all

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <EEPROM.h>
  
Adafruit_BNO055 bnoA = Adafruit_BNO055(-1, BNO055_ADDRESS_A);
Adafruit_BNO055 bnoB = Adafruit_BNO055(-1, BNO055_ADDRESS_B);
#define BNO055_SAMPLERATE_DELAY_MS (100)


/**************************************************************************/
/*  Non-Fusion  
 *    Configuration mode = CONFIG (default)
 *    Accel and gyro = ACCGYRO 
 *  Initialize and Calibrate IMU  */
/**************************************************************************/

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

    bnoA.begin(OPERATION_MODE_ACCGYRO);   
    bnoA.setExtCrystalUse(true);
    bnoA.setRanges();

    bnoB.begin(OPERATION_MODE_ACCGYRO);
    bnoB.setExtCrystalUse(true);
    bnoB.setRanges();

    delay(500);
}

void loop(void) 
{
  //Functions to retrieve and send serial data

  getAcc();
  getGyro();
  
  delay(BNO055_SAMPLERATE_DELAY_MS);
}

void getAcc() {
  double xA = -1000, yA = -1000 , zA = -1000 , xB = -1000 , yB = -1000 , zB = -1000; //dumb values, easy to spot problem
  
  imu::Vector<3> accA = bnoA.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
    xA = accA.x();
    yA = accA.y();
    zA = accA.z();

  imu::Vector<3> accB = bnoB.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
    xB = accB.x();
    yB = accB.y();
    zB = accB.z();    

    Serial.print("Acc 1:");
    Serial.print(" | x= ");
    Serial.print(xA);
    Serial.print(" | y= ");
    Serial.print(yA);
    Serial.print(" | z= ");
    Serial.print(zA);

    Serial.print(" | Acc 2:");
    Serial.print(" | x= ");
    Serial.print(xB);
    Serial.print(" | y= ");
    Serial.print(yB);
    Serial.print(" | z= ");
    Serial.print(zB);

}

void getGyro() {
  double xA = -1000, yA = -1000 , zA = -1000 , xB = -1000 , yB = -1000 , zB = -1000;
  
  imu::Vector<3> gyroA = bnoA.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
    xA = gyroA.x(); 
    yA = gyroA.y();   
    zA = gyroA.z();
    
  imu::Vector<3> gyroB = bnoB.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
    xB = gyroB.x(); 
    yB = gyroB.y();   
    zB = gyroB.z();
    
    Serial.print(" | Gyro 1:");
    Serial.print(" | x= ");
    Serial.print(xA);
    Serial.print(" | y= ");
    Serial.print(yA);
    Serial.print(" | z= ");
    Serial.print(zA);

    Serial.print(" | Gyro 2:");
    Serial.print(" | x= ");
    Serial.print(xB);
    Serial.print(" | y= ");
    Serial.print(yB);
    Serial.print(" | z= ");
    Serial.println(zB);
}

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO055 Sensor Zeroing All Values

Post by gammaburst »

Hi Jake_CSU,
Which microcontroller are you using?
Are your two BNO055s connected with Qwiic cables? How long?
Or connected some other way (show a photo)?
Which version of the BNO055 library are you using?

I built your code on an Arduino Uno, and connected two BNO055s with short Qwiic cables.
I jumpered the second BNO055 for secondary I2C address.
I had to comment-out the two lines with setRanges() because my libraries don't have that function.
Your code runs fine for me, both sensors running, no stuck-at-zero.

Be sure you've updated your libraries and boards (use Library Manager and Board Manager).
Last edited by gammaburst on Tue Nov 15, 2022 2:35 pm, edited 1 time in total.

User avatar
Jake_CSU
 
Posts: 4
Joined: Tue Nov 15, 2022 1:39 pm

Re: BNO055 Sensor Zeroing All Values

Post by Jake_CSU »

Gammaburst,

I am using an Arduino Uno. My setup photo is below, with the following connections:

Arduino 5V to Vin on both BNO055s
Arduino GND to GND on both BNO055s
Arduino A5 to SCL on both BNO055s
Arduino A4 to SDA on both BNO055s
3Vo to ADR on BNO055 2.
Setup.jpg
Setup.jpg (25.32 KiB) Viewed 206 times
I am using the library found here: https://github.com/adafruit/Adafruit_BNO055
I did edit the library to add the following function to set the sensor ranges to +-8G and +-500 dps

Code: Select all

/*!
/*	@brief Writes to the sensors range settings	
*/

void Adafruit_BNO055::setRanges()
{
  adafruit_bno055_opmode_t modeback = _mode;
  
  /* switch to config mode */
  setMode(OPERATION_MODE_CONFIG);
  delay(25);
  
  /* save selected page ID and switch ACC page (1) */
  uint8_t savePageID = read8(BNO055_PAGE_ID_ADDR);
  write8(BNO055_PAGE_ID_ADDR, 0x01);
  
  /* set configuration to 8G range */
  write8(BNO055_ACCEL_REV_ID_ADDR, 0x02);
  delay(10);

  /* switch to GYR page */
  write8(BNO055_PAGE_ID_ADDR, 0x03);
  delay(10);

  /* set gyro configuration to 500 dps */
  write8(BNO055_GYRO_REV_ID_ADDR, 0x02);
  delay(10);
  
  /* restore page ID */
  write8(BNO055_PAGE_ID_ADDR, savePageID);
  
  /* set the requested operating mode */
  setMode(modeback);
  delay(20); 
}
Mine does not zero out until after a minute or two of moving around the sensors.

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO055 Sensor Zeroing All Values

Post by gammaburst »

Did the problem occur before you modified the library? Try an unmodified library.

Mine has been running many minutes without failing, however all BNO055 projects are on the verge of failure due to a BNO055 design fault, possibly exacerbated by your longer I2C wires. If you have a spare resistor, about 2K to 3K ohms, try connecting it from SDA to VIN on one of the BNOs. See if that eliminates your bogus zero data. If you don't have a resistor, we'll try another trick. If it works, I'll explain why.

User avatar
Jake_CSU
 
Posts: 4
Joined: Tue Nov 15, 2022 1:39 pm

Re: BNO055 Sensor Zeroing All Values

Post by Jake_CSU »

Without the setRanges() function it is no longer printing zeros, so I guess that is most likely where my problem is

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO055 Sensor Zeroing All Values

Post by gammaburst »

Maybe, but now that you've mentioned the zeros appear after a couple minutes, that smells more like the BNO055 I2C problem (possibly cured by the resistor), and less likely caused by your library modification (I wouldn't expect it to cause an intermittent problem). Maybe!

I can provoke my BNOs to output some zeros by simply connecting a short wire to signal SDA and firmly grabbing its bare end with two fingers. Finger capacitance slows SDA's risetime (and exacerbates the BNO's I2C design fault), the extra resistor speeds-up SDA's risetime (helps avoid the BNO's design fault). I recommend adding the resistor. It may help your project run fine even with your library modification. (I haven't tried your modification.)

User avatar
Jake_CSU
 
Posts: 4
Joined: Tue Nov 15, 2022 1:39 pm

Re: BNO055 Sensor Zeroing All Values

Post by Jake_CSU »

Ok, thank you for the advice! I do not have a resistor on hand at my current location, but will test that out when I can. My understanding was that the BNO has 10k pullup resistors connected to the SDA and SCL pins, can you explain to me how this additional resistor speeds up the SDA risetime?

I will also revisit my library modification to ensure everything is correct there, but I had the same intuition that the library mod would not cause the zeroing out after a minute or so.

User avatar
gammaburst
 
Posts: 1013
Joined: Thu Dec 31, 2015 12:06 pm

Re: BNO055 Sensor Zeroing All Values

Post by gammaburst »

Here's more info about the BNO's I2C timing problem and why the extra-resistor workaround helps:
viewtopic.php?p=889629#p889629

The extra pullup resistor speeds-up SDA's rise-time because it's an open-collector (open-drain) driven signal. A transistor inside the microcontroller or BNO055 turns on strongly to quickly pull the signal low. The transistor turns off to allow the external pullup resistor to pull the signal high. The signal wire has some distributed capacitance to ground, so rise-time equals the familiar R*C time constant expression. My extra 2K to 3K resistor decreases R, so rise-time also decreases (speeds-up). That helps overcome the BNO's timing problem as I described at the above-mentioned URL.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wearables”