Arduino - error check for compass - QMC5883L

how could i create a functioning check on a sensor, i want to confirm it is working in the code, say with a boolean? I want to create an error or a success message on boot up.

I tried writing this with compass.init() but it does not run.

here is a code snippet from my program, also im running this via multiplexor system.

//////////////////////////////////////////////////////////////////////////// COMPASS ACTIVATE

  tcaSelect(bus2);               // enable I2C channel 2
  Wire.beginTransmission(addr2);

  if(compass.init()){
    Serial.println("compass Init failed!");
  }
  else{

  compass.setCalibration(-428, 656, -2357, 0, 0, 980);

  Serial.println("Compass init Success & Calibrated");
  }
  
  Wire.endTransmission();

error message

exit status 1

Compilation error: could not convert 'compass.QMC5883LCompass::init()' from 'void' to 'bool'

and here is a standard example of the compass

/*
===============================================================================================================
QMC5883LCompass.h Library Azimuth Example Sketch
Learn more at [https://github.com/mprograms/QMC5883Compas]
===============================================================================================================
v0.3 - June 12, 2019
Written by MRPrograms 
Github: [https://github.com/mprograms/]

Release under the GNU General Public License v3
[https://www.gnu.org/licenses/gpl-3.0.en.html]
===============================================================================================================
*/
#include <QMC5883LCompass.h>

QMC5883LCompass compass;

void setup() {
  Serial.begin(9600);
  compass.init();
  
}

void loop() {
  int a;
  
  // Read compass values
  compass.read();

  // Return Azimuth reading
  a = compass.getAzimuth();
  
  Serial.print("A: ");
  Serial.print(a);
  Serial.println();
  
  delay(250);
}

Please post all the code in question, and explain what you mean by "multiplexor system".

Please also explain what you mean by "it does not run", and post the error messages.

sorry multiplexor is a generic term and is just added in for context.. it can be ignored.. I have added in the error message now. cheers :slight_smile:

The error message is clear. The .init function does not return a value.

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