AHRS library Calibration Tutorial

I have loaded the AHRS Adafruit library into my arduino. I am following your AHRS tutorial for the LSM6DS33 and LIS3MDL. However, once I get to the step of the Adafruit AHR Calibration, I get the following error:

Loaded existing calibration
Failed to find sensors

I am using the Mega2560 board with the I2C connections. Please help. Thank you.

Welcome to the forum.

Take a step back.
Are your modules with the sensors compatible with a 5V Arduino board ?
Can you run a I2C Scanner sketch to check if the I2C bus is working ?
Can you give a link to that tutorial ?

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

Which tutorial?

Ok, thank you.

The tutorial is here:

In response to the questions from Koepel. I am using the Arduino Mega2560 board, with the LSM6DS33 + LIS3MDL chip. It is connected to the Vin-Vin, GND-GND, SCL-SCL (21), SDA-SDA(20).

From everything I see, it is the correct type of board and sensors per the tutorial. Thank you.

Have you had a response to an I2C scanner sketch?

Thank you,

I just ran an I2C scanner using the code from this tutorial:


And it gave me this error:

C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino:1:1: error: expected unqualified-id before '/' token
/ ---------------------------------------------------------------- /
In file included from C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino:11:0:
C:\Users\T\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\Wire\src/Wire.h:86:8: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
extern TwoWire Wire;
C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino: In function 'void setup()':
C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino:15:3: error: 'Wire' was not declared in this scope
Wire.begin(); // Wire communication begin
C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino: In function 'void loop()':
C:\Users\T\AppData\Local\Temp.arduinoIDE-unsaved202282-1436-dt3rkl.194er\sketch_sep2a\sketch_sep2a.ino:34:5: error: 'Wire' was not declared in this scope

exit status 1

Compilation error: expected unqualified-id before '/' token

Whoever published that is an idiot. Take everything out before the #include <Wire.h> //include Wire.h library. The problem is the two lines that start with a single forward slash; that should have been two.

There is also a scanner in the IDE somewhere.

Exactly as @sterretje said. Not sure why others have not reported the same problem.

Adafruit makes their sensor modules compatible for 3.3V Arduino boards and for 5V Arduino boards. Can you give links to you sensor modules ?

You need a I2C Scanner to be sure that the I2C bus is working.
I'm sorry that you found the only I2C Scanner sketch that does not work :person_facepalming:
I turned it into a working one:

#include <Wire.h>

void setup()
  Serial.begin(9600); // The baudrate of Serial monitor is set in 9600
  Serial.println("\nI2C Scanner");
  Wire.begin(); // Wire communication begin

void loop()
  byte error, address; //variable for error and I2C address
  int nDevices;


  nDevices = 0;
  for (address = 1; address < 127; address++ )
    error = Wire.endTransmission();

    if (error == 0)
      Serial.print("I2C device found at address 0x");
      if (address < 16)
      Serial.print(address, HEX);
      Serial.println("  !");
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");


For the others: The header of that wrong sketch also forgot to mention that it is just a copy of the I2C Scanner sketch in the Playground. Nick Gammon has a I2C Scanner sketch.

Thank you all for your help. I followed your instructions and it worked.

It said:

I2C device found at address 0x1C
I2C device found at address0x6A

Here is a link to the integrated Adafruit sensor I am using.

Thank you all again for your help.

Very good :sunglasses:

Now we can continue with your question about the AHRS software using the tutorial.

Is that tutorial for your sensor board ?
Which steps did you take and where is the step for the AHRS Calibration ? (which sketch, using software on your computer or just the Arduino board).

Thank you!

That tutorial does not specify exactly which sensors. From everything I see, it fits that tutorial. I also have the Clue board and would use that if necessary.

I made it successfully through the tutorial to the Calibration Write Check step, where I got the error for failed to find sensors.

Thank you,

That is not easy.
It seems that the calibration sketch is already set to your sensor board. If you have not changed the address of the sensors, then it should work, I think.
I assume that you have installed the "Adafruit AHRS" library with all the libraries that it needs ?
Then you could try an example from the LSM6DS33 library and a example from the LIS3MDL. For example this one and this one. They are in the menu of the Arduino IDE.

Are you sure that you have not changed something to the library and that you have the latest versions of all the libraries ?

Adafruit has extra layers of libraries, so they don't have to write the same code over and over again. But now they have layers of code on top of layers of code, and it is hard to see what is going on.

Loaded existing calibration
Failed to find sensors

The sensor calibration program and AHRS program are completely independent, but they communicate via calibration data stored in EEPROM.

It looks to me like you have not correctly set up the AHRS program for the sensors you are actually using.

I gave up on Adafruit device libraries long ago, because they have become so bloated and try to hide every detail from the user.

The accelerometer and magnetometer sensors can be individually calibrated using a more hands-on approach, which is what Adafruit is trying to hide from you, by following the basic outlines in this forum post. If you work your way through that, in the end you should understand what is actually happening.

Fantastic, thank you both so much! I will reach out with any additional questions.

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