Skip to content

Commit 903c7d2

Browse files
committed
example edits
1 parent 4a26868 commit 903c7d2

File tree

14 files changed

+436
-226
lines changed

14 files changed

+436
-226
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
#include "SparkFun_SGP30_Library.h"
1+
/*
2+
Library for the Sensirion SGP30 Indoor Air Quality Sensor
3+
By: Ciara Jekel
4+
SparkFun Electronics
5+
Date: June 28th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SGP30 Datasheet: https://cdn.sparkfun.com/assets/4/7/d/f/b/Sensirion_SGP30_Datasheet.pdf
9+
10+
Feel like supporting our work? Buy a board from SparkFun!
11+
https://www.sparkfun.com/products/14813
12+
13+
This example reads the sensors calculated CO2 and TVOC values
14+
*/
15+
16+
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
217
#include <Wire.h>
318

419
SGP30 mySensor; //create an object of the SGP30 class
5-
byte count = 0;
620

721
void setup() {
822
Serial.begin(9600);
923
Wire.begin();
24+
//Sensor supports I2C speeds up to 400kHz
1025
Wire.setClock(400000);
26+
//Initialize sensor
1127
mySensor.begin();
28+
//Initializes sensor for air quality readings
1229
mySensor.initAirQuality();
13-
//ignore first 15 readings
14-
while (count < 15) {
15-
delay(1000); //Wait 1 second
16-
mySensor.measureAirQuality();
17-
count++;
18-
}
1930
}
2031

2132
void loop() {
33+
//First fifteen readings will be
34+
//CO2: 400 ppm TVOC: 0 ppb
2235
delay(1000); //Wait 1 second
36+
//measure CO2 and TVOC levels
2337
mySensor.measureAirQuality();
2438
Serial.print("CO2: ");
2539
Serial.print(mySensor.CO2);
26-
Serial.print(" ppm\tTVOC");
40+
Serial.print(" ppm\tTVOC: ");
2741
Serial.print(mySensor.TVOC);
2842
Serial.println(" ppb");
2943

examples/Example2_Baseline/Example2_Baseline.ino

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Library for the Sensirion SGP30 Indoor Air Quality Sensor
3+
By: Ciara Jekel
4+
SparkFun Electronics
5+
Date: June 28th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SGP30 Datasheet: https://cdn.sparkfun.com/assets/4/7/d/f/b/Sensirion_SGP30_Datasheet.pdf
9+
10+
Feel like supporting our work? Buy a board from SparkFun!
11+
https://www.sparkfun.com/products/14813
12+
13+
This example reads the sensors calculated CO2 and
14+
TVOC values and the raw values for H2 and ethanol.
15+
*/
16+
17+
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
18+
#include <Wire.h>
19+
20+
SGP30 mySensor; //create an object of the SGP30 class
21+
22+
void setup() {
23+
Serial.begin(9600);
24+
Wire.begin();
25+
//Sensor supports I2C speeds up to 400kHz
26+
Wire.setClock(400000);
27+
//Initialize sensor
28+
mySensor.begin();
29+
//Initializes sensor for air quality readings
30+
mySensor.initAirQuality();
31+
32+
}
33+
34+
void loop() {
35+
//First fifteen readings will be
36+
//CO2: 400 ppm TVOC: 0 ppb
37+
delay(1000); //Wait 1 second
38+
//measure CO2 and TVOC levels
39+
mySensor.measureAirQuality();
40+
Serial.print("CO2: ");
41+
Serial.print(mySensor.CO2);
42+
Serial.print(" ppm\tTVOC: ");
43+
Serial.print(mySensor.TVOC);
44+
Serial.println(" ppb");
45+
//get raw values for H2 and Ethanol
46+
mySensor.measureRawSignals();
47+
Serial.print("Raw H2: ");
48+
Serial.print(mySensor.H2);
49+
Serial.print(" \tRaw Ethanol: ");
50+
Serial.println(mySensor.ethanol);
51+
}

examples/Example3_Humidity/Example3_Humidity.ino

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
/*
2+
Library for the Sensirion SGP30 Indoor Air Quality Sensor
3+
By: Ciara Jekel
4+
SparkFun Electronics
5+
Date: June 28th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SGP30 Datasheet: https://cdn.sparkfun.com/assets/4/7/d/f/b/Sensirion_SGP30_Datasheet.pdf
29
3-
4-
This example uses the Si7021 to get relative humidity
10+
Feel like supporting our work? Buy a board from SparkFun!
11+
https://www.sparkfun.com/products/14813
12+
13+
This example gets relative humidity from a sensor, convertts it to absolute humidty,
14+
and updates the SGP30's humidity compensation with the absolute humidity value.
515
*/
616

7-
8-
#include "SparkFun_SGP30_Library.h"
9-
#include "SparkFun_Si7021_Breakout_Library.h"
17+
#include "SparkFun_SGP30_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
1019
#include <Wire.h>
1120

1221
SGP30 mySensor; //create an instance of the SGP30 class
@@ -18,9 +27,9 @@ void setup() {
1827
Serial.begin(9600);
1928
Wire.begin();
2029
Wire.setClock(400000);
21-
//Initialize the SGP30
30+
//Initialize the SGP30
2231
mySensor.begin();
23-
32+
2433
//Initialize the humidity sensor and ping it
2534
hSensor.begin();
2635
// Measure Relative Humidity from the Si7021
@@ -31,32 +40,30 @@ void setup() {
3140
double absHumidity = RHtoAbsolute(humidity, temperature);
3241
//Convert the double type humidity to a fixed point 8.8bit number
3342
uint16_t sensHumidity = doubleToFixedPoint(absHumidity);
43+
//Initializes sensor for air quality readings
44+
mySensor.initAirQuality();
3445
//Set the humidity compensation on the SGP30 to the measured value
46+
//If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
3547
mySensor.setHumidity(sensHumidity);
36-
37-
//ignore first 15 readings
38-
mySensor.initAirQuality();
39-
while (count < 15) {
40-
delay(1000); //Wait 1 second
41-
mySensor.measureAirQuality();
42-
count++;
43-
}
48+
4449
}
4550

4651
void loop() {
52+
//First fifteen readings will be
53+
//CO2: 400 ppm TVOC: 0 ppb
4754
delay(1000); //Wait 1 second
4855
mySensor.measureAirQuality();
4956
Serial.print("CO2: ");
5057
Serial.print(mySensor.CO2);
51-
Serial.print(" ppm\tTVOC");
58+
Serial.print(" ppm\tTVOC: ");
5259
Serial.print(mySensor.TVOC);
5360
Serial.println(" ppb");
5461

5562
}
5663

5764
double RHtoAbsolute (float relHumidity, float tempC) {
58-
double Es = 6.11 * pow(10.0, (7.5 * tempC / (237.7 + tempC)));
59-
double vaporPressure = (relHumidity * Es) / 100; //millibars
65+
double eSat = 6.11 * pow(10.0, (7.5 * tempC / (237.7 + tempC)));
66+
double vaporPressure = (relHumidity * eSat) / 100; //millibars
6067
double absHumidity = 1000 * vaporPressure * 100 / ((tempC + 273) * 461.5); //Ideal gas law with unit conversions
6168
}
6269

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Library for the Sensirion SGP30 Indoor Air Quality Sensor
3+
By: Ciara Jekel
4+
SparkFun Electronics
5+
Date: June 28th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SGP30 Datasheet: https://cdn.sparkfun.com/assets/4/7/d/f/b/Sensirion_SGP30_Datasheet.pdf
9+
10+
Feel like supporting our work? Buy a board from SparkFun!
11+
https://www.sparkfun.com/products/14813
12+
13+
This example measures CO2 and TVOC and reports any errors.
14+
*/
15+
16+
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
17+
#include <Wire.h>
18+
19+
SGP30 mySensor; //create an object of the SGP30 class
20+
SGP30ERR error;
21+
22+
void setup() {
23+
Serial.begin(9600);
24+
Wire.begin();
25+
//Sensor supports I2C speeds up to 400kHz
26+
Wire.setClock(400000);
27+
//Initialize sensor
28+
mySensor.begin();
29+
//Initializes sensor for air quality readings
30+
mySensor.initAirQuality();
31+
}
32+
33+
void loop() {
34+
//First fifteen readings will be
35+
//CO2: 400 ppm TVOC: 0 ppb
36+
delay(1000); //Wait 1 second
37+
//measure CO2 and TVOC levels
38+
error = mySensor.measureAirQuality();
39+
if (error == SUCCESS) {
40+
Serial.print("CO2: ");
41+
Serial.print(mySensor.CO2);
42+
Serial.print(" ppm\tTVOC: ");
43+
Serial.print(mySensor.TVOC);
44+
Serial.println(" ppb");
45+
}
46+
else if (error == ERR_BAD_CRC) {
47+
Serial.println("CRC Failed");
48+
}
49+
else if (error == ERR_I2C_TIMEOUT) {
50+
Serial.println("I2C Timed out");
51+
}
52+
}

examples/Example4_RawSignals/Example4_RawSignals.ino

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/Example5_DeviceInfo/Example5_DeviceInfo.ino

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
#include "SparkFun_SGP30_Library.h"
1+
/*
2+
Library for the Sensirion SGP30 Indoor Air Quality Sensor
3+
By: Ciara Jekel
4+
SparkFun Electronics
5+
Date: June 28th, 2018
6+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
SGP30 Datasheet: https://cdn.sparkfun.com/assets/4/7/d/f/b/Sensirion_SGP30_Datasheet.pdf
9+
10+
Feel like supporting our work? Buy a board from SparkFun!
11+
https://www.sparkfun.com/products/14813
12+
13+
This example gets the sensor's serial ID and version number.
14+
*/
15+
16+
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
217
#include <Wire.h>
318

419
SGP30 mySensor; //create an object of the SGP30 class
5-
byte count = 0;
620

721
void setup() {
822
Serial.begin(9600);
923
Wire.begin();
24+
//Sensor supports I2C speeds up to 400kHz
1025
Wire.setClock(400000);
26+
//Initialize sensor
1127
mySensor.begin();
28+
//Get SGP30's ID
1229
mySensor.getSerialID();
30+
//Get version number
1331
mySensor.getFeatureSetVersion();
1432
Serial.print("SerialID: 0x");
15-
Serial.print((uint32_t)(mySensor.serialID >> 32), HEX);
16-
Serial.print((uint32_t)mySensor.serialID, HEX);
33+
Serial.print((unsigned long)mySensor.serialID, HEX);
1734
Serial.print("\tFeature Set Version: 0x");
18-
Serial.print(mySensor.featureSetVersion, HEX);
35+
Serial.println(mySensor.featureSetVersion, HEX);
1936
}
2037

2138
void loop() {

0 commit comments

Comments
 (0)