Skip to content

Commit

Permalink
Update bbn_m5atomS3_lite_TVOC_SGP30.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Oct 30, 2024
1 parent 7756e4c commit 6665766
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions bbn_m5atomS3_lite_TVOC_SGP30/bbn_m5atomS3_lite_TVOC_SGP30.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_SGP30.h>
#include "NmeaXDR.h"
#include "NmeaChecksum.h"

Adafruit_SGP30 sgp;

Expand All @@ -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);
}
}

0 comments on commit 6665766

Please sign in to comment.