Skip to content

Commit 83105b9

Browse files
author
Nathan Seidle
committed
2 parents ab84992 + b9d04dc commit 83105b9

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
SparkFun SGP30 Library
22
===========================================================
3-
[![SparkX SGP30 Breakout (Qwiic) (SPX-14813)](https://cdn.sparkfun.com/assets/parts/1/3/0/8/1/14813-SGP30_Breakout__Qwiic_-01.jpg)](https://www.sparkfun.com/products/14813)
3+
[![SparkFun Air Quality Sensor - SGP30 (Qwiic) (SEN-16531)](https://cdn.sparkfun.com/assets/parts/1/5/4/0/9/16531-SparkFun_Air_Quality_Sensor_-_SGP30__Qwiic_-05.jpg)](https://www.sparkfun.com/products/16531)
44

5-
[*SparkX SGP30 Breakout (Qwiic) (SPX-14813)*](https://www.sparkfun.com/products/14813)
5+
[*SparkFun Air Quality Sensor - SGP30 (Qwiic) (SEN-16531)*](https://www.sparkfun.com/products/16531)
66

77
The SGP30 is an indoor air quality sensor equipped with an I<sup>2</sup>C interface. It outputs equivalent CO<sub>2</sub> in ppm and Total Volatile Organic Compounds (TVOC) in ppb. The sensor also gives access to its raw measurement values of Ethanol and H<sub>2</sub>.
88

99
The SGP30 boasts high stability with low long term drift. With its continuous baseline compensation algorithm, readings stay accurate over time. You can even fine tune your readings by interfacing with an external humidity sensor to add humidity compensation.
1010
While the CCS811 requires a burn-in of 48 hours and a run-in of 20 minutes the SGP30 is ready to go after just 15 seconds.
1111

1212
SparkFun labored with love to create this code. Feel like supporting open source hardware?
13-
Buy a [board](https://www.sparkfun.com/products/14813) from SparkFun!
13+
Buy a [board](https://www.sparkfun.com/products/16531) from SparkFun!
1414

1515
Shout outs to all those folks that have helped make this library better:
1616

@@ -29,7 +29,14 @@ Documentation
2929
--------------
3030

3131
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
32-
* **[Product Repository](https://github.com/sparkfunX/Qwiic-SGP30-Breakout)** - Main repository (including hardware files)
32+
* **[Product Repository](https://github.com/sparkfun/SparkFun_Air_Quality_Sensor-SGP30)** - Main repository (including hardware files)
33+
* **[SGP30 Hookup Guide](https://learn.sparkfun.com/tutorials/sparkfun-air-quality-sensor---sgp30-qwiic-hookup-guide)** - A short hookup guide to get started with the SparkFun Air Quality Sensor - SGP30 (Qwiic)
34+
35+
Products that use this library
36+
--------------
37+
* [SEN-16531](https://www.sparkfun.com/products/16531)- SparkFun Version 1.0
38+
* [SPX-14813](https://www.sparkfun.com/products/14813)- SparkX Version
39+
3340

3441
License Information
3542
-------------------

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)