10
10
Feel like supporting our work? Buy a board from SparkFun!
11
11
https://www.sparkfun.com/products/14813
12
12
13
- This example gets relative humidity from a sensor, convertts it to absolute humidty,
13
+ This example gets relative humidity from a sensor, converts it to absolute humidty,
14
14
and updates the SGP30's humidity compensation with the absolute humidity value.
15
15
*/
16
16
@@ -36,17 +36,23 @@ void setup() {
36
36
37
37
// Initialize the humidity sensor and ping it
38
38
hSensor.begin ();
39
+
39
40
// Measure Relative Humidity from the Si7021
40
41
float humidity = hSensor.getRH ();
42
+
41
43
// Measure temperature (in C) from the Si7021
42
44
float temperature = hSensor.getTemp ();
45
+
43
46
// Convert relative humidity to absolute humidity
44
47
double absHumidity = RHtoAbsolute (humidity, temperature);
48
+
45
49
// Convert the double type humidity to a fixed point 8.8bit number
46
50
uint16_t sensHumidity = doubleToFixedPoint (absHumidity);
51
+
47
52
// Initializes sensor for air quality readings
48
53
// measureAirQuality should be called in one second increments after a call to initAirQuality
49
54
mySensor.initAirQuality ();
55
+
50
56
// Set the humidity compensation on the SGP30 to the measured value
51
57
// If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
52
58
mySensor.setHumidity (sensHumidity);
@@ -56,10 +62,9 @@ void setup() {
56
62
void loop () {
57
63
// First fifteen readings will be
58
64
// CO2: 400 ppm TVOC: 0 ppb
59
- t2 = millis ();
60
- if ( t2 >= t1 + 1000 ) // only will occur if 1 second has passed
65
+ if ( millis () >= t1 + 1000 ) // only will occur if 1 second has passed
61
66
{
62
- t1 = t2 ; // measure CO2 and TVOC levels
67
+ t1 = millis () ; // measure CO2 and TVOC levels
63
68
mySensor.measureAirQuality ();
64
69
Serial.print (" CO2: " );
65
70
Serial.print (mySensor.CO2 );
@@ -82,5 +87,3 @@ uint16_t doubleToFixedPoint( double number) {
82
87
uint16_t value = floor (number2 + 0.5 );
83
88
return value;
84
89
}
85
-
86
-
0 commit comments