use sparkfun lib for sensors adafruit has issues
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include "VOC_sensor.h"
|
||||
#define DEBUG_SERIAL
|
||||
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
//Adafruit_SGP30 sgp;
|
||||
SGP30 sgp;
|
||||
|
||||
//TwoWire wire1(1);
|
||||
uint8_t VOC_samples = 3600 / g_pms_report_period;
|
||||
#define VOC_MIN 0
|
||||
#define VOC_MAX 10000
|
||||
@@ -17,21 +22,25 @@ AQSSensor SGP30_rawethanol("Raw_Ethanol", SGP30_rawEthanol, "#", device_name, VO
|
||||
void initVOCsensor(void)
|
||||
{
|
||||
Serial.println("VOCSensor: Init SGP30: ");
|
||||
|
||||
//wire1.setPins(I2C_2_SDA, I2C_2_SCL);
|
||||
//if (!sgp.begin(&wire1))
|
||||
Wire.begin();
|
||||
if (!sgp.begin())
|
||||
{
|
||||
Serial.println("VOCSensor: Init Failed (SGP30 not found)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.printf("VOCSensor: serial =0x%X%X%X\n", sgp.serialnumber[0], sgp.serialnumber[1], sgp.serialnumber[2]);
|
||||
sgp.getSerialID();
|
||||
//Get version number
|
||||
sgp.getFeatureSetVersion();
|
||||
Serial.print("VOCSensor: serial =0x");
|
||||
Serial.println((unsigned long)sgp.serialID, HEX);
|
||||
addSensorToList(&SGP30_tvoc);
|
||||
addSensorToList(&SGP30_eco2);
|
||||
addSensorToList(&SGP30_rawh2);
|
||||
addSensorToList(&SGP30_rawethanol);
|
||||
|
||||
sgp.IAQmeasure();
|
||||
sgp.IAQmeasureRaw();
|
||||
sgp.initAirQuality();
|
||||
sgp.measureAirQuality();
|
||||
|
||||
Serial.println("VOCSensor: Init OK");
|
||||
}
|
||||
@@ -42,29 +51,14 @@ void handleVOCsensor(void)
|
||||
uint32_t timenow = millis();
|
||||
if ((timenow - lastVOCtime > VOC_INTERVAL) || !lastVOCtime)
|
||||
{
|
||||
if (!sgp.IAQmeasure())
|
||||
{
|
||||
Serial.println("VOCSensor: Measurement failed");
|
||||
return;
|
||||
}
|
||||
sgp.measureAirQuality();
|
||||
|
||||
SGP30_tvoc.set(sgp.TVOC);
|
||||
SGP30_eco2.set(sgp.eCO2);
|
||||
SGP30_eco2.set(sgp.CO2);
|
||||
|
||||
SGP30_tvoc.publish();
|
||||
SGP30_eco2.publish();
|
||||
|
||||
if (!sgp.IAQmeasureRaw())
|
||||
{
|
||||
Serial.println("VOCSensor: Raw Measurement failed");
|
||||
return;
|
||||
}
|
||||
|
||||
SGP30_rawethanol.set(sgp.rawEthanol);
|
||||
SGP30_rawh2.set(sgp.rawH2);
|
||||
|
||||
SGP30_rawethanol.publish();
|
||||
SGP30_rawh2.publish();
|
||||
|
||||
lastVOCtime = timenow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user