Jay Jay
Jay Jay

Reputation: 1

Problems with BNO055 (Arduino)

I'm facing a problem that I've tried everything and it doesn't solve it. I just want to read the acceleration on the serial monitor and plotter for now, the code runs, works and is OK, I've already changed and tested the Arduino, sensor, breadboard... and it's OK. everything works normally but it simply repeats the initial line start 0, in other words, it's as if it didn't have a sensor, it simply doesn't read, it doesn't update. Sometimes it spikes and shows different values ​​for a few seconds or right at the beginning, but it's very rare. I'm already hoping that the libraries are downloaded and working correctly, the port settings are correct, I've already soldered the sensor (tested it again, it works) and it's connected to +5v, so I'm suspecting that it might not work for this sensor, which is a cheaper version of the original (but with the same name: BNO055) or it could be a protocol error too, anyway I have no idea what it could be. (Ignore the MPU in the image, I was using it to test)

Source code:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <math.h>

#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 myIMU = Adafruit_BNO055();

float thetaM;
float phiM;
float thetaFold = 0;
float thetaFnew;
float phiFold = 0;
float phiFnew;

void setup() {
  Serial.begin(115200);
  myIMU.begin();
  delay(1000);
  int8_t temp = myIMU.getTemp();
  // Serial.printIn(temp);
  myIMU.setExtCrystalUse(true);
}

void loop() {
  uint8_t system, gyro, accel, mg = 0;
  myIMU.getCalibration(&system, &gyro, &accel, &mg);

  imu::Vector<3> acc = myIMU.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  thetaM = -atan2(acc.x() / 9.8, acc.z() /9.8) / 2/ 3.141592654 * 360;
  phiM = atan2(acc.y() / 9.8, acc.z() / 9.8) / 2/ 3.141592654 * 360;

  thetaFnew = .9 * thetaFold + .1 * thetaM;
  phiFnew = .9 * phiFold + .1 * phiM;

  Serial.print(acc.x() / 9.8);
  Serial.print(",");
  Serial.print(acc.y() / 9.8);
  Serial.print(",");
  Serial.print(acc.z() / 9.8);
  Serial.print(",");

  Serial.print(accel);
  Serial.print(",");
  Serial.print(gyro);
  Serial.print(",");
  Serial.print(mg);
  Serial.print(",");

  Serial.print(system);
  Serial.print(",");
  
  Serial.print(thetaM);
  Serial.print(",");
  Serial.print(phiM);

  Serial.print(thetaFnew);
  Serial.print(",");
  Serial.println(phiFnew);

  phiFold = phiFnew;
  thetaFold = thetaFnew;

  delay(BNO055_SAMPLERATE_DELAY_MS);
}

monitor

circuit

Upvotes: 0

Views: 145

Answers (1)

Lee-xp
Lee-xp

Reputation: 870

It would be useful to check whether your device has initialised correctly. Use something like:

if (!myIMU.begin()) {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("No BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
}

in setup().

Also check that you are using the correct I2C address.

It is probably a good idea to try to run this example code from Adafruit. If this works it will give you a very good starting point. Interestingly their example uses an I2C address of 0x37. This is the 55 in this line Adafruit_BNO055 bno = Adafruit_BNO055(55); But I am wondering if this is a typo - in which case you should try it with Adafruit_BNO055().

Upvotes: 1

Related Questions