Skip to content

Commit 039bfd4

Browse files
committed
minor edits
name change removed blocking delay from examples 2+ changed library to use fixed delay while waiting for sensor to measure changed begin function to bool updated keywords added issue template
1 parent 9f03e63 commit 039bfd4

File tree

14 files changed

+162
-151
lines changed

14 files changed

+162
-151
lines changed

ISSUE_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Subject of the issue
2+
Describe your issue here.
3+
4+
### Your workbench
5+
* What platform are you using?
6+
* What version of the device are you using? Is there a firmware version?
7+
* How is the device wired to your platform?
8+
* How is everything being powered?
9+
* Are there any additional details that may help us help you?
10+
11+
### Steps to reproduce
12+
Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue to a gist.
13+
14+
### Expected behaviour
15+
Tell us what should happen
16+
17+
### Actual behaviour
18+
Tell us what happens instead

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
This example reads the sensors calculated CO2 and TVOC values
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1717
#include <Wire.h>
1818

1919
SGP30 mySensor; //create an object of the SGP30 class
@@ -22,7 +22,7 @@ void setup() {
2222
Serial.begin(9600);
2323
Wire.begin();
2424
//Initialize sensor
25-
if (mySensor.begin() != SUCCESS) {
25+
if (mySensor.begin() == false) {
2626
Serial.println("No SGP30 Detected. Check connections.");
2727
while (1);
2828
}

examples/Example2_RawSignals/Example2_RawSignals.ino

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,45 @@
1414
TVOC values and the raw values for H2 and ethanol.
1515
*/
1616

17-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
17+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1818
#include <Wire.h>
1919

2020
SGP30 mySensor; //create an object of the SGP30 class
21-
21+
long t1, t2;
2222
void setup() {
2323
Serial.begin(9600);
2424
Wire.begin();
2525
//Sensor supports I2C speeds up to 400kHz
2626
Wire.setClock(400000);
2727
//Initialize sensor
28-
if (mySensor.begin() != SUCCESS) {
28+
if (mySensor.begin() == false) {
2929
Serial.println("No SGP30 Detected. Check connections.");
3030
while (1);
3131
}
3232
//Initializes sensor for air quality readings
3333
mySensor.initAirQuality();
34-
34+
t1 = millis();
3535
}
3636

3737
void loop() {
3838
//First fifteen readings will be
3939
//CO2: 400 ppm TVOC: 0 ppb
40-
delay(1000); //Wait 1 second
41-
//measure CO2 and TVOC levels
42-
mySensor.measureAirQuality();
43-
Serial.print("CO2: ");
44-
Serial.print(mySensor.CO2);
45-
Serial.print(" ppm\tTVOC: ");
46-
Serial.print(mySensor.TVOC);
47-
Serial.println(" ppb");
48-
//get raw values for H2 and Ethanol
49-
mySensor.measureRawSignals();
50-
Serial.print("Raw H2: ");
51-
Serial.print(mySensor.H2);
52-
Serial.print(" \tRaw Ethanol: ");
53-
Serial.println(mySensor.ethanol);
40+
t2 = millis();
41+
if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
42+
{
43+
t1 = t2;
44+
//measure CO2 and TVOC levels
45+
mySensor.measureAirQuality();
46+
Serial.print("CO2: ");
47+
Serial.print(mySensor.CO2);
48+
Serial.print(" ppm\tTVOC: ");
49+
Serial.print(mySensor.TVOC);
50+
Serial.println(" ppb");
51+
//get raw values for H2 and Ethanol
52+
mySensor.measureRawSignals();
53+
Serial.print("Raw H2: ");
54+
Serial.print(mySensor.H2);
55+
Serial.print(" \tRaw Ethanol: ");
56+
Serial.println(mySensor.ethanol);
57+
}
5458
}

examples/Example3_Humidity/Example3_Humidity.ino

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
and updates the SGP30's humidity compensation with the absolute humidity value.
1515
*/
1616

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

2121
SGP30 mySensor; //create an instance of the SGP30 class
2222
Weather hSensor; //create an instance of the Weather class
23+
long t1, t2;
2324

2425
byte count = 0;
2526

@@ -28,7 +29,7 @@ void setup() {
2829
Wire.begin();
2930
Wire.setClock(400000);
3031
//Initialize the SGP30
31-
if (mySensor.begin() != SUCCESS) {
32+
if (mySensor.begin() == false) {
3233
Serial.println("No SGP30 Detected. Check connections.");
3334
while (1);
3435
}
@@ -48,20 +49,23 @@ void setup() {
4849
//Set the humidity compensation on the SGP30 to the measured value
4950
//If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
5051
mySensor.setHumidity(sensHumidity);
51-
52+
t1 = millis();
5253
}
5354

5455
void loop() {
5556
//First fifteen readings will be
5657
//CO2: 400 ppm TVOC: 0 ppb
57-
delay(1000); //Wait 1 second
58-
mySensor.measureAirQuality();
59-
Serial.print("CO2: ");
60-
Serial.print(mySensor.CO2);
61-
Serial.print(" ppm\tTVOC: ");
62-
Serial.print(mySensor.TVOC);
63-
Serial.println(" ppb");
64-
58+
t2 = millis();
59+
if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
60+
{
61+
t1 = t2; //measure CO2 and TVOC levels
62+
mySensor.measureAirQuality();
63+
Serial.print("CO2: ");
64+
Serial.print(mySensor.CO2);
65+
Serial.print(" ppm\tTVOC: ");
66+
Serial.print(mySensor.TVOC);
67+
Serial.println(" ppb");
68+
}
6569
}
6670

6771
double RHtoAbsolute (float relHumidity, float tempC) {

examples/Example4_ErrorChecking/Example4_ErrorChecking.ino

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,48 @@
1313
This example measures CO2 and TVOC and reports any errors.
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1717
#include <Wire.h>
1818

1919
SGP30 mySensor; //create an object of the SGP30 class
2020
SGP30ERR error;
21+
long t1, t2;
2122

2223
void setup() {
2324
Serial.begin(9600);
2425
Wire.begin();
2526
//Sensor supports I2C speeds up to 400kHz
2627
Wire.setClock(400000);
2728
//Initialize sensor
28-
if (mySensor.begin() != SUCCESS) {
29+
if (mySensor.begin() == false) {
2930
Serial.println("No SGP30 Detected. Check connections.");
3031
while (1);
3132
}
3233
//Initializes sensor for air quality readings
3334
mySensor.initAirQuality();
35+
t1 = millis();
3436
}
3537

3638
void loop() {
3739
//First fifteen readings will be
3840
//CO2: 400 ppm TVOC: 0 ppb
39-
delay(1000); //Wait 1 second
40-
//measure CO2 and TVOC levels
41-
error = mySensor.measureAirQuality();
42-
if (error == SUCCESS) {
43-
Serial.print("CO2: ");
44-
Serial.print(mySensor.CO2);
45-
Serial.print(" ppm\tTVOC: ");
46-
Serial.print(mySensor.TVOC);
47-
Serial.println(" ppb");
48-
}
49-
else if (error == ERR_BAD_CRC) {
50-
Serial.println("CRC Failed");
51-
}
52-
else if (error == ERR_I2C_TIMEOUT) {
53-
Serial.println("I2C Timed out");
41+
t2 = millis();
42+
if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
43+
{
44+
t1 = t2; //measure CO2 and TVOC levels
45+
error = mySensor.measureAirQuality();
46+
if (error == SUCCESS) {
47+
Serial.print("CO2: ");
48+
Serial.print(mySensor.CO2);
49+
Serial.print(" ppm\tTVOC: ");
50+
Serial.print(mySensor.TVOC);
51+
Serial.println(" ppb");
52+
}
53+
else if (error == ERR_BAD_CRC) {
54+
Serial.println("CRC Failed");
55+
}
56+
else if (error == ERR_I2C_TIMEOUT) {
57+
Serial.println("I2C Timed out");
58+
}
5459
}
5560
}

examples/Example5_DeviceInfo/Example5_DeviceInfo.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
This example gets the sensor's serial ID and version number.
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1717
#include <Wire.h>
1818

1919
SGP30 mySensor; //create an object of the SGP30 class
@@ -24,7 +24,7 @@ void setup() {
2424
//Sensor supports I2C speeds up to 400kHz
2525
Wire.setClock(400000);
2626
//Initialize sensor
27-
if (mySensor.begin() != SUCCESS) {
27+
if (mySensor.begin() == false) {
2828
Serial.println("No SGP30 Detected. Check connections.");
2929
while (1);
3030
}

examples/Example6_SchedulerReadings/Example6_SchedulerReadings.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
freeing the main loop from wasteful delays.
1515
*/
1616

17-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
17+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1818
#include <TaskScheduler.h> // Click here to get the library: http://librarymanager/All#TaskScheduler
1919
#include <Wire.h>
2020

@@ -30,7 +30,7 @@ void setup() {
3030
Serial.begin(9600);
3131
Wire.begin();
3232
Wire.setClock(400000);
33-
if (mySensor.begin() != SUCCESS) {
33+
if (mySensor.begin() == false) {
3434
Serial.println("No SGP30 Detected. Check connections.");
3535
while (1);
3636
}

examples/Example7_Reset/Example7_Reset.ino

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
This example performs a soft reset on the sensor and restores its baseline.
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1717
#include <Wire.h>
1818
#include <EEPROM.h>
19+
long t1, t2;
1920

2021
SGP30 mySensor; //create an object of the SGP30 class
2122
byte baselineC02Addr = 0x00;
@@ -25,7 +26,7 @@ void setup() {
2526
Serial.begin(9600);
2627
Wire.begin();
2728
Wire.setClock(400000);
28-
if (mySensor.begin() != SUCCESS) {
29+
if (mySensor.begin() == false) {
2930
Serial.println("No SGP30 Detected. Check connections.");
3031
while (1);
3132
}
@@ -64,15 +65,19 @@ void setup() {
6465
//set the sensor's baseline to the previously gotten baseline
6566
mySensor.setBaseline(mySensor.baselineCO2, mySensor.baselineTVOC);
6667
Serial.println("Updated Baseline");
68+
t1 = millis();
6769
}
6870

6971
void loop() {
70-
delay(1000); //Wait 1 second
71-
mySensor.measureAirQuality();
72-
Serial.print("CO2: ");
73-
Serial.print(mySensor.CO2);
74-
Serial.print(" ppm\t TVOC: ");
75-
Serial.print(mySensor.TVOC);
76-
Serial.println(" ppb");
77-
72+
t2 = millis();
73+
if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
74+
{
75+
t1 = t2; //measure CO2 and TVOC levels
76+
mySensor.measureAirQuality();
77+
Serial.print("CO2: ");
78+
Serial.print(mySensor.CO2);
79+
Serial.print(" ppm\tTVOC: ");
80+
Serial.print(mySensor.TVOC);
81+
Serial.println(" ppb");
82+
}
7883
}

examples/Example8_OtherI2C/Example8_OtherI2C.ino

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,36 @@
1313
This example reads the sensors calculated CO2 and TVOC values using Software Wire
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
1717
#include <SoftwareWire.h>
1818

1919
SGP30 mySensor; //create an object of the SGP30 class
20+
long t1, t2;
2021

2122
void setup() {
2223
Serial.begin(9600);
2324
//Initialize sensor, specifying I2C port
24-
if (mySensor.begin(Wire) != SUCCESS) {
25+
if (mySensor.begin(Wire) == false) {
2526
Serial.println("No SGP30 Detected. Check connections.");
2627
while (1);
2728
}
2829
//Initializes sensor for air quality readings
2930
mySensor.initAirQuality();
31+
t1 = millis();
3032
}
3133

3234
void loop() {
3335
//First fifteen readings will be
3436
//CO2: 400 ppm TVOC: 0 ppb
35-
delay(1000); //Wait 1 second
36-
//measure CO2 and TVOC levels
37-
mySensor.measureAirQuality();
38-
Serial.print("CO2: ");
39-
Serial.print(mySensor.CO2);
40-
Serial.print(" ppm\tTVOC: ");
41-
Serial.print(mySensor.TVOC);
42-
Serial.println(" ppb");
43-
37+
t2 = millis();
38+
if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
39+
{
40+
t1 = t2; //measure CO2 and TVOC levels
41+
mySensor.measureAirQuality();
42+
Serial.print("CO2: ");
43+
Serial.print(mySensor.CO2);
44+
Serial.print(" ppm\tTVOC: ");
45+
Serial.print(mySensor.TVOC);
46+
Serial.println(" ppb");
47+
}
4448
}

examples/Example9_UnitTest/Example9_UnitTest.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
This example performs the sensor's self test and displays the results.
1414
*/
1515

16-
#include "SparkFun_SGP30_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30#include <Wire.h>
16+
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30#include <Wire.h>
1717

1818
SGP30 mySensor; //create an object of the SGP30 class
1919
byte count = 0;
@@ -22,10 +22,11 @@ void setup() {
2222
Serial.begin(9600);
2323
Wire.begin();
2424
Wire.setClock(400000);
25-
if (mySensor.begin() != SUCCESS) {
25+
if (mySensor.begin() == false) {
2626
Serial.println("No SGP30 Detected. Check connections.");
2727
while (1);
2828
}
29+
//measureTest() should not be called after a call to initAirQuality()
2930
error = mySensor.measureTest();
3031
if (error == SUCCESS) {
3132
Serial.println("Success!");

keywords.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ SUCCESS LITERAL1
3838
ERR_BAD_CRC LITERAL1
3939
ERR_I2C_TIMEOUT LITERAL1
4040
SELF_TEST_FAIL LITERAL1
41-
SparkFun_SGP30_Library_h LITERAL1
42-
SparkFun_SGP30_Library.h LITERAL1
41+
SparkFun_SGP30_Arduino_Library_h LITERAL1
42+
SparkFun_SGP30_Arduino_Library.h LITERAL1
4343
init_air_quality LITERAL1
4444
measure_air_quality LITERAL1
4545
get_baseline LITERAL1
@@ -48,4 +48,5 @@ set_humidity LITERAL1
4848
measure_test LITERAL1
4949
get_feature_set_version LITERAL1
5050
get_serial_id LITERAL1
51-
measure_raw_signals LITERAL1
51+
measure_raw_signals LITERAL1
52+
SGP30_LOOKUP_TABLE LITERAL1

0 commit comments

Comments
 (0)