BNO055 Sensor

Does anyone have experience with the BNO055 compass? Its a very accurate sensor and it works great however every time the Arduino restarts the compass has to re calibrate. Im creating an auto pilot program which will require the compass to already be calibrated at the start. I cant keep recalibrating it every time. Does anyone know how to retain the calibration? Ive tried this sketch but it wont keep the calibration.

You need to tell us more about your setup.
What model Arduino are you using?
What messages are printed on the serial monitor on first run of the Adafruit sketch?
What messages do you get after resetting the Arduino?

Have you read the data sheet? It tells you: The following section describes the register holding the calibration data of the sensors (see chapter 3.10). The offset and radius data can be read from these registers and stored in the host system, your arduino, which could be later used to get the correct orientation data after ‘Power on Reset’ of the sensor. Note there is no way to bypass the Power on Reset of the sensor, it is inherent in its construction. There are a lot of application notes for this device as well, I highly recommend you search for them and then read them, this will help a lot.

Ill look over the documentation again.
I've searched a bunch for a way to load the saved data but no luck. I have an Arduino Uno. I was able to run the calibration by changing the scl and sda pins and moved them to A5 and A4 pins. So that part is fixed, but im still not clear on how to save the calibration so i can access it in another sketch. I'll keep searching for a way. If anyone knows how i'd appreciate some help.

The Adafruit sketch you linked to appears to tests if the device has been calibrated and if not does calibration and stores the results in EEPROM.

What results do you get on the serial monitor when you run the sketch and then again when you reset the UNO (Not reprogram it). Re-programming the UNO may wipe the EEPROM memory so it would ask for calibration after this.

If the sketch is working as expected then you should only be asked to calibrate on first use and after that resetting the UNO it should load the calibrated data and continue.
If this is the case then you can incorporate the relevant calibration & EEPROM write/read code from the sketch into your own or add your code to the Adafruit sketch.

so that sketch i linked to wasnt working for me, it would allow me to go through the calibration phase however, once the sensor was fully calibrated, it never continued on to setting the calibration data in the EEPROM. I had to modify the code in order for it to work. Now, once the the sensor is calibrated, it runs the code to store the data and set the sensor data. Heres the updated portion of the sketch that worked for me. I basically updated the loop to check for a calibrated status of true, if true then updated the memory with the new calibration data.

void loop() {
    /* Get a new sensor event */
    sensors_event_t event;
    bno.getEvent(&event);

    /* Display the floating point data */
    Serial.print("X: ");
    Serial.print(event.orientation.x, 4);
    Serial.print("\tY: ");
    Serial.print(event.orientation.y, 4);
    Serial.print("\tZ: ");
    Serial.print(event.orientation.z, 4);

    /* Optional: Display calibration status */
    displayCalStatus();

    /* Optional: Display sensor status (debug only) */
    //displaySensorStatus();

    /* New line for the next sample */
    Serial.println("");

    if(bno.isFullyCalibrated())
    {
      
        Serial.println("\nFully calibrated!");
        Serial.println("--------------------------------");
        Serial.println("Calibration Results: ");
        adafruit_bno055_offsets_t newCalib;
        bno.getSensorOffsets(newCalib);
        displaySensorOffsets(newCalib);
    
        Serial.println("\n\nStoring calibration data to EEPROM...");
    
        eeAddress = 0;
        bno.getSensor(&sensor);
        bnoID = sensor.sensor_id;
    
        EEPROM.put(eeAddress, bnoID);
    
        eeAddress += sizeof(long);
        EEPROM.put(eeAddress, newCalib);
        Serial.println("Data stored to EEPROM.");
    
        Serial.println("\n--------------------------------\n");
      
    }
    
    /* Wait the specified delay before requesting new data */
    delay(BNO055_SAMPLERATE_DELAY_MS);
}

So now, when i upload a different sketch to use the compass, i add the following

int eeAddress = 0;
  long bnoID;
  bool foundCalib = false;

  EEPROM.get(eeAddress, bnoID);

  adafruit_bno055_offsets_t calibrationData;
  sensor_t sensor;

  bno.getSensor(&sensor);
  
  if (bnoID != sensor.sensor_id)
  {
      Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
      delay(500);
  }
  else
  {
      Serial.println("\nFound Calibration for this sensor in EEPROM.");
      eeAddress += sizeof(long);
      EEPROM.get(eeAddress, calibrationData);

      //displaySensorOffsets(calibrationData);

      Serial.println("\n\nRestoring Calibration data to the BNO055...");
      bno.setSensorOffsets(calibrationData);

      displaySensorOffsets(calibrationData);
      
      Serial.println("\n\nCalibration data loaded into BNO055");
      foundCalib = true;
  }

works great for me! Hope this helps someone else out.

1 Like

Glad you got the problem sorted out.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.