Skip to content

Commit 486eba0

Browse files
committed
Update Example3_Humidity and Version Bump
Updating Example3_Humidity to use the SHTC3 instead of Si7021. Added function to reset humidity value with an updated reading in case users want to have a "live" update to this value. Library version updated to 1.0.3
1 parent 2dba398 commit 486eba0

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

examples/Example3_Humidity/Example3_Humidity.ino

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616

1717
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
18-
#include "SparkFun_Si7021_Breakout_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_Si7021
18+
#include "SparkFun_SHTC3.h" // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
1919
#include <Wire.h>
2020

2121
SGP30 mySensor; //create an instance of the SGP30 class
22-
Weather hSensor; //create an instance of the Weather class
22+
SHTC3 humiditySensor; //create an instance of the SHTC3 class
2323
long t1, t2;
2424

2525
byte count = 0;
@@ -35,13 +35,15 @@ void setup() {
3535
}
3636

3737
//Initialize the humidity sensor and ping it
38-
hSensor.begin();
38+
humiditySensor.begin();
39+
// Call "update()" to command a measurement, wait for measurement to complete, and update the RH and T members of the object
40+
SHTC3_Status_TypeDef result = humiditySensor.update();
41+
delay(190);
42+
// Measure Relative Humidity from the SHTC3
43+
float humidity = humiditySensor.toPercent();
3944

40-
// Measure Relative Humidity from the Si7021
41-
float humidity = hSensor.getRH();
42-
43-
//Measure temperature (in C) from the Si7021
44-
float temperature = hSensor.getTemp();
45+
//Measure temperature (in C) from the SHTC3
46+
float temperature = humiditySensor.toDegC();
4547

4648
//Convert relative humidity to absolute humidity
4749
double absHumidity = RHtoAbsolute(humidity, temperature);
@@ -56,6 +58,10 @@ void setup() {
5658
//Set the humidity compensation on the SGP30 to the measured value
5759
//If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
5860
mySensor.setHumidity(sensHumidity);
61+
Serial.print("Absolute humidity compensation set to: ");
62+
Serial.print(absHumidity);
63+
Serial.println("g/m^3 ");
64+
delay(100);
5965
t1 = millis();
6066
}
6167

@@ -72,6 +78,34 @@ void loop() {
7278
Serial.print(mySensor.TVOC);
7379
Serial.println(" ppb");
7480
}
81+
if (Serial.available()) //check if new data is available on serial port
82+
{
83+
char ch = Serial.read();
84+
if (ch == 'h' || ch == 'H') //check if the char input matches either "h" or "H" and if it does, run the compensation routine from the setup
85+
{
86+
SHTC3_Status_TypeDef result = humiditySensor.update();
87+
delay(190);
88+
// Measure Relative Humidity from the SHTC3
89+
float humidity = humiditySensor.toPercent();
90+
91+
//Measure temperature (in C) from the SHTC3
92+
float temperature = humiditySensor.toDegC();
93+
94+
//Convert relative humidity to absolute humidity
95+
double absHumidity = RHtoAbsolute(humidity, temperature);
96+
97+
//Convert the double type humidity to a fixed point 8.8bit number
98+
uint16_t sensHumidity = doubleToFixedPoint(absHumidity);
99+
100+
//Set the humidity compensation on the SGP30 to the measured value
101+
//If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
102+
mySensor.setHumidity(sensHumidity);
103+
Serial.print("Absolute Humidity Compensation set to: ");
104+
Serial.print(absHumidity);
105+
Serial.println("g/m^3 ");
106+
delay(100);
107+
}
108+
}
75109
}
76110

77111
double RHtoAbsolute (float relHumidity, float tempC) {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun SGP30 Arduino Library
2-
version=1.0.2
2+
version=1.0.3
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=Library for the Sensirion SGP30 air quality sensor

0 commit comments

Comments
 (0)