Compile issue when combining multiple sensors

All - I have 4 devices (Pulse Oximeter, UV index, Air Quality, LCD display) connected on I2C to Arduino Uno and am able to get the sensors to work. I then integrated SGP30 sensor and started getting compile error issues. I then removed all code and just combined Sparkfun Pulse Oximeter sensor & the SGP sensor - this is still giving the same compile error ("Error compiling for board Arduino Uno"). Note that they all work individually ok.

Any thoughts on how I can debug this or what the issue could be? Appreciate any help here..

#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>
#include "SparkFun_SGP30_Arduino_Library.h"
SGP30 mySensor; //create an object of the SGP30 class
// Reset pin, MFIO pin
int resPin = 4;
int mfioPin = 5;

// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin); 

bioData body;  
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>
#include <SparkFun_SGP30_Arduino_Library.h>
SGP30 mySensor; //create an object of the SGP30 class
// Reset pin, MFIO pin
int resPin = 4;
int mfioPin = 5;

// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin); 

bioData body; 

void setup(){

  Serial.begin(115200);

  Wire.begin();
  int result = bioHub.begin();
  if (result == 0) // Zero errors!
    Serial.println("Sensor started!");
  else
    Serial.println("Could not communicate with the sensor!!!");
 
  Serial.println("Configuring Sensor...."); 
  int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings. 
  if(error == 0){ // Zero errors!
    Serial.println("Sensor configured.");
  }
  else {
    Serial.println("Error configuring sensor.");
    Serial.print("Error: "); 
    Serial.println(error); 
  }

  // Data lags a bit behind the sensor, if you're finger is on the sensor when
  // it's being configured this delay will give some time for the data to catch
  // up. 
  Serial.println("Loading up the buffer with data....");

  //Initialize sensor
  if (mySensor.begin() == false) {
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
  
  delay(4000); 
  
}

void loop(){

    // Information from the readBpm function will be saved to our "body"
    // variable.  
    body = bioHub.readBpm();
    Serial.print("Heartrate: ");
    Serial.println(body.heartRate); 
    Serial.print("Confidence: ");
    Serial.println(body.confidence); 
    Serial.print("Oxygen: ");
    Serial.println(body.oxygen); 
    Serial.print("Status: ");
    Serial.println(body.status); 

  delay(1000); //Wait 1 second
  //measure CO2 and TVOC levels
  mySensor.measureAirQuality();
  Serial.print("CO2: ");
  Serial.print(mySensor.CO2);
  Serial.print(" ppm\tTVOC: ");
  Serial.print(mySensor.TVOC);
  Serial.println(" ppb");
  delay(250); 
}

Post the error messages

Here is the error message:


In file included from C:\Users\ANIKAB~1\AppData\Local\Temp\arduino_modified_sketch_552235\Example1_config_BPM_Mode1.ino:29:0:
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src/SparkFun_SGP30_Arduino_Library.h:46:13: error: redeclaration of 'SUCCESS'
SUCCESS = 0,
^
In file included from C:\Users\ANIKAB~1\AppData\Local\Temp\arduino_modified_sketch_552235\Example1_config_BPM_Mode1.ino:27:0:
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_Bio_Sensor_Hub_Library-master\src/SparkFun_Bio_Sensor_Hub_Library.h:73:3: note: previous declaration 'READ_STATUS_BYTE_VALUE SUCCESS'
SUCCESS = 0x00,
^~~~~~~
exit status 1
Error compiling for board Arduino Uno.


The problem is that both libraries are polluting the namespace with a very generic and common (most especially for SparkFun libraries apparently) name SUCCESS:
https://github.com/sparkfun/SparkFun_SGP30_Arduino_Library/blob/83105b9d7c6a7171540ee068968eb7f6d1b0905f/src/SparkFun_SGP30_Arduino_Library.h#L46-L50

typedef enum
{
  SUCCESS = 0,
  ERR_BAD_CRC,
  ERR_I2C_TIMEOUT,
  SELF_TEST_FAIL
} SGP30ERR;
// Status Bytes are communicated back after every I-squared-C transmission and
// are indicators of success or failure of the previous transmission.
enum READ_STATUS_BYTE_VALUE {

  SUCCESS                  = 0x00,
  ERR_UNAVAIL_CMD,
  ERR_UNAVAIL_FUNC,
  ERR_DATA_FORMAT,
  ERR_INPUT_VALUE,
  ERR_TRY_AGAIN,
  ERR_BTLDR_GENERAL        = 0x80,
  ERR_BTLDR_CHECKSUM,
  ERR_BTLDR_AUTH,
  ERR_BTLDR_INVALID_APP,
  ERR_UNKNOWN              = 0xFF

};

The workaround is to change lines 1-3 of your sketch from:

#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>
#include "SparkFun_SGP30_Arduino_Library.h"

to:

#define SUCCESS SparkFun_SGP30_Arduino_Library_SUCCESS
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#undef SUCCESS
#define SUCCESS SparkFun_Bio_Sensor_Hub_Library_SUCCESS
#include "SparkFun_SGP30_Arduino_Library.h"

Then make sure to use the right identifier if using those enums in your sketch.

Don't get confused by the fact that you have pointless redundant #include directives for these header files in your sketch. The second set of the #include directives in your sketch do nothing (so you might as well delete them).

Thank you so much for debugging this - that worked!!

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

Hi - just following up on this:

One other question I had, which I just noticed: the program compiled fine, but when scrolling up the compile window, I noticed the following messages. Is this ok or do I need to fix these? If so, any pointers?

C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src/SparkFun_SGP30_Arduino_Library.h:50:3: warning: type 'SGP30ERR' violates the C++ One Definition Rule [-Wodr]
} SGP30ERR;
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src\SparkFun_SGP30_Arduino_Library.h:50:3: note: an enum with different value name is defined in another translation unit
} SGP30ERR;
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src/SparkFun_SGP30_Arduino_Library.h:89:12: warning: 'measureAirQuality' violates the C++ One Definition Rule [-Wodr]
SGP30ERR measureAirQuality(void);
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src\SparkFun_SGP30_Arduino_Library.cpp:80:10: note: return value type mismatch
SGP30ERR SGP30::measureAirQuality(void)
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src\SparkFun_SGP30_Arduino_Library.h:50:3: note: type 'SGP30ERR' itself violates the C++ One Definition Rule
} SGP30ERR;
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src/SparkFun_SGP30_Arduino_Library.h:50:3: note: the incompatible type is defined here
} SGP30ERR;
^
C:\Users\Anika Bhat\OneDrive\Documents\Arduino\libraries\SparkFun_SGP30_Arduino_Library-master\src\SparkFun_SGP30_Arduino_Library.cpp:80:10: note: 'measureAirQuality' was previously declared here
SGP30ERR SGP30::measureAirQuality(void)
^
Sketch uses 8176 bytes (25%) of program storage space. Maximum is 32256 bytes.
Global variables use 781 bytes (38%) of dynamic memory, leaving 1267 bytes for local variables. Maximum is 2048 bytes.

OK, this is a side effect of the workaround I described. I don't think it could cause any problems, but even just the warnings are annoying.

Since, unlike the SparkFun_SGP30_Arduino_Library library, the SparkFun_Bio_Sensor_Hub_Library library doesn't actually use its conflicting enum in the .cpp file, I think you can fix this by only doing the workaround for the SparkFun_Bio_Sensor_Hub_Library library. So change these lines of your sketch:

#define SUCCESS SparkFun_SGP30_Arduino_Library_SUCCESS
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#undef SUCCESS
#define SUCCESS SparkFun_Bio_Sensor_Hub_Library_SUCCESS
#include "SparkFun_SGP30_Arduino_Library.h"

to:

#define SUCCESS SparkFun_Bio_Sensor_Hub_Library_SUCCESS
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#undef SUCCESS
#include "SparkFun_SGP30_Arduino_Library.h"

Thanks! it helped a lot

Thank you for helping close these warning - this worked.

I'm glad to hear it!

It helps me too, thanks for the tips.