diff --git a/bbn_m5atomS3_lite_TVOC_SGP30/bbn_m5atomS3_lite_TVOC_SGP30.ino b/bbn_m5atomS3_lite_TVOC_SGP30/bbn_m5atomS3_lite_TVOC_SGP30.ino index 99687c3..431794d 100644 --- a/bbn_m5atomS3_lite_TVOC_SGP30/bbn_m5atomS3_lite_TVOC_SGP30.ino +++ b/bbn_m5atomS3_lite_TVOC_SGP30/bbn_m5atomS3_lite_TVOC_SGP30.ino @@ -2,6 +2,8 @@ #include #include #include +#include "NmeaXDR.h" +#include "NmeaChecksum.h" Adafruit_SGP30 sgp; @@ -11,52 +13,48 @@ void setup() { Serial.begin(4800); Wire.begin(); Wire.setClock(100000); - Serial.printf("SGP30 before init\n"); delay(10); - if (!sgp.begin(&Wire)) { // Init the sensor. + if (!sgp.begin(&Wire, true)) { // Init the sensor. while (1) ; } - Serial.printf("SGP30 init\n"); - Serial.print("Found SGP30 serial #"); - Serial.print(sgp.serialnumber[0], HEX); - Serial.print(sgp.serialnumber[1], HEX); - Serial.println(sgp.serialnumber[2], HEX); + //Serial.print("Found SGP30 serial #"); + //Serial.print(sgp.serialnumber[0], HEX); + //Serial.print(sgp.serialnumber[1], HEX); + //Serial.println(sgp.serialnumber[2], HEX); } int counter = 0; void loop() { - // If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals + // If you have a temperature / humidity sensor, you can set the absolute humidity + // to enable the humditiy compensation for the air quality signals + //float temperature = 22.1; // [°C] //float humidity = 45.2; // [%RH] //sgp.setHumidity(getAbsoluteHumidity(temperature, humidity)); - if (!sgp.IAQmeasure()) { - // Commands the sensor to take a single eCO2/VOC measurement. - //Serial.println("Measurement failed"); + // Commands the sensor to take a single eCO2/VOC measurement. + if (!sgp.IAQmeasure()) { + // Measurement failed return; } - Serial.printf("TVOC:%d ppb\n", sgp.TVOC); - Serial.printf("eCO2:%d ppm\n", sgp.eCO2); + gen_nmea0183_xdr("$BBXDR,X,%.0f,,TVOC", sgp.TVOC); // ppb + gen_nmea0183_xdr("$BBXDR,X,%.0f,,eCO2", sgp.eCO2); // ppm if (! sgp.IAQmeasureRaw()) { - Serial.println("Raw Measurement failed"); + // Raw Measurement failed return; } - Serial.printf("rawH2:%d\n", sgp.rawH2); - Serial.printf("rawEthanol2:%d\n", sgp.rawEthanol); + gen_nmea0183_xdr("$BBXDR,X,%.0f,,rawH2", sgp.rawH2); + gen_nmea0183_xdr("$BBXDR,X,%.0f,,rawEthanol", sgp.rawEthanol); delay(1000); counter++; if (counter == 30) { counter = 0; - uint16_t TVOC_base, eCO2_base; if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) { - Serial.println("Failed to get baseline readings"); return; } - Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX); - Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX); } }