Hi - I am able to work individual I2C sensors correctly; however, when I combine them, I am running into problems. I currently have SGP30 and Pulse Oximeter & HR monitor sensor (both SparkFun). Here is the code:
#define SUCCESS SparkFun_SGP30_Arduino_Library_SUCCESS //The problem is that both libraries are polluting the namespace
//with a generic and common name `SUCCESS`l was giving compilation error
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#undef SUCCESS
#define SUCCESS SparkFun_Bio_Sensor_Hub_Library_SUCCESS //not really needed
#include "SparkFun_SGP30_Arduino_Library.h"
#include <Wire.h>
// Include the SparkFun VEML6075 (UV Sensor) library.
// Click here to get the library: http://librarymanager/All#SparkFun_VEML6075
SGP30 mySensor; //create an object of the SGP30 class
// No other Address options.
#define DEF_ADDR 0x55
// Reset pin, MFIO pin
const int resPin = 4;
const int mfioPin = 5;
unsigned long clocktime;
// 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)
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){
Serial.println("Sensor configured.");
}
else {
Serial.println("Error configuring sensor.");
Serial.print("Error: ");
Serial.println(error);
}
//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);
digitalWrite(13, HIGH); //turn-off the blue LED
if (body.status == 3 && body.confidence > 90) {
digitalWrite(13, LOW); //turn-on the blue LED
}
// Use the uva, uvb, and index functions to read calibrated UVA and UVB values and a
// calculated UV index value between 0-11.
//First fifteen readings will be
//CO2: 400 ppm TVOC: 0 ppb
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(1000); // Slowing it down, we don't need to break our necks here.
}
********************end Code********
When I compile this code, it does compile ok, but I didn't note the messages above the compile message until recently; is this something I have to fix? See below for the message I see:
*********************
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.
**********