Skip to content

Commit 4a26868

Browse files
committed
Initial commit
0 parents  commit 4a26868

File tree

14 files changed

+860
-0
lines changed

14 files changed

+860
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
SparkFun License Information
2+
============================
3+
4+
SparkFun uses two different licenses for our files — one for hardware and one for code.
5+
6+
Hardware
7+
---------
8+
9+
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**
10+
11+
Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).
12+
13+
You are free to:
14+
15+
Share — copy and redistribute the material in any medium or format
16+
Adapt — remix, transform, and build upon the material
17+
for any purpose, even commercially.
18+
The licensor cannot revoke these freedoms as long as you follow the license terms.
19+
Under the following terms:
20+
21+
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
22+
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
23+
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
24+
Notices:
25+
26+
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
27+
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
28+
29+
30+
Code
31+
--------
32+
33+
**SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**
34+
35+
The MIT License (MIT)
36+
37+
Copyright (c) 2016 SparkFun Electronics
38+
39+
Permission is hereby granted, free of charge, to any person obtaining a copy
40+
of this software and associated documentation files (the "Software"), to deal
41+
in the Software without restriction, including without limitation the rights
42+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43+
copies of the Software, and to permit persons to whom the Software is
44+
furnished to do so, subject to the following conditions:
45+
46+
The above copyright notice and this permission notice shall be included in all
47+
copies or substantial portions of the Software.
48+
49+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55+
SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
SparkFun SGP30 Library
2+
===========================================================
3+
![]()
4+
5+
[*SparkX SGP30 Breakout (Qwiic) (SPX-14813)*](https://www.sparkfun.com/products/14813)
6+
7+
8+
Repository Contents
9+
-------------------
10+
11+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
12+
* **/src** - Source files for the library (.cpp, .h).
13+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
14+
* **library.properties** - General library properties for the Arduino package manager.
15+
16+
Documentation
17+
--------------
18+
19+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
20+
* **[Product Repository](https://github.com/sparkfunX/Qwiic_LED_Stick)** - Main repository (including hardware files)
21+
22+
License Information
23+
-------------------
24+
25+
This product is _**open source**_!
26+
27+
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.
28+
29+
Distributed as-is; no warranty is given.
30+
31+
- Your friends at SparkFun.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
4+
SGP30 mySensor; //create an object of the SGP30 class
5+
byte count = 0;
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
Wire.begin();
10+
Wire.setClock(400000);
11+
mySensor.begin();
12+
mySensor.initAirQuality();
13+
//ignore first 15 readings
14+
while (count < 15) {
15+
delay(1000); //Wait 1 second
16+
mySensor.measureAirQuality();
17+
count++;
18+
}
19+
}
20+
21+
void loop() {
22+
delay(1000); //Wait 1 second
23+
mySensor.measureAirQuality();
24+
Serial.print("CO2: ");
25+
Serial.print(mySensor.CO2);
26+
Serial.print(" ppm\tTVOC");
27+
Serial.print(mySensor.TVOC);
28+
Serial.println(" ppb");
29+
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
#include <EEPROM.h>
4+
5+
SGP30 mySensor; //create an object of the SGP30 class
6+
byte count = 0;
7+
byte baselineC02Addr = 0x00;
8+
byte baselineTVOCAddr = 0x02;
9+
void setup() {
10+
Serial.begin(9600);
11+
Wire.begin();
12+
Wire.setClock(400000);
13+
mySensor.begin();
14+
mySensor.initAirQuality();
15+
//ignore first 15 readings
16+
while (count < 15) {
17+
delay(1000); //Wait 1 second
18+
mySensor.measureAirQuality();
19+
count++;
20+
}
21+
}
22+
23+
void loop() {
24+
delay(1000); //Wait 1 second
25+
mySensor.measureAirQuality();
26+
Serial.print("CO2: ");
27+
Serial.print(mySensor.CO2);
28+
Serial.print(" ppm\tTVOC");
29+
Serial.print(mySensor.TVOC);
30+
Serial.println(" ppb");
31+
mySensor.getBaseline();
32+
if (count == 30) {
33+
EEPROM.put(baselineC02Addr, mySensor.baselineCO2);
34+
EEPROM.put(baselineTVOCAddr, mySensor.baselineTVOC);
35+
}
36+
if (count == 33) {
37+
EEPROM.get(baselineC02Addr, mySensor.baselineCO2);
38+
EEPROM.get(baselineTVOCAddr, mySensor.baselineTVOC);
39+
mySensor.setBaseline(mySensor.baselineCO2, mySensor.baselineTVOC);
40+
41+
}
42+
count++;
43+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
3+
4+
This example uses the Si7021 to get relative humidity
5+
*/
6+
7+
8+
#include "SparkFun_SGP30_Library.h"
9+
#include "SparkFun_Si7021_Breakout_Library.h"
10+
#include <Wire.h>
11+
12+
SGP30 mySensor; //create an instance of the SGP30 class
13+
Weather hSensor; //create an instance of the Weather class
14+
15+
byte count = 0;
16+
17+
void setup() {
18+
Serial.begin(9600);
19+
Wire.begin();
20+
Wire.setClock(400000);
21+
//Initialize the SGP30
22+
mySensor.begin();
23+
24+
//Initialize the humidity sensor and ping it
25+
hSensor.begin();
26+
// Measure Relative Humidity from the Si7021
27+
float humidity = hSensor.getRH();
28+
//Measure temperature (in C) from the Si7021
29+
float temperature = hSensor.getTemp();
30+
//Convert relative humidity to absolute humidity
31+
double absHumidity = RHtoAbsolute(humidity, temperature);
32+
//Convert the double type humidity to a fixed point 8.8bit number
33+
uint16_t sensHumidity = doubleToFixedPoint(absHumidity);
34+
//Set the humidity compensation on the SGP30 to the measured value
35+
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+
}
44+
}
45+
46+
void loop() {
47+
delay(1000); //Wait 1 second
48+
mySensor.measureAirQuality();
49+
Serial.print("CO2: ");
50+
Serial.print(mySensor.CO2);
51+
Serial.print(" ppm\tTVOC");
52+
Serial.print(mySensor.TVOC);
53+
Serial.println(" ppb");
54+
55+
}
56+
57+
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
60+
double absHumidity = 1000 * vaporPressure * 100 / ((tempC + 273) * 461.5); //Ideal gas law with unit conversions
61+
}
62+
63+
uint16_t doubleToFixedPoint( double number) {
64+
int power = 1 << 8;
65+
double number2 = number * power;
66+
uint16_t value = floor(number2 + 0.5);
67+
return value;
68+
}
69+
70+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
4+
SGP30 mySensor; //create an object of the SGP30 class
5+
byte count = 0;
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
Wire.begin();
10+
Wire.setClock(400000);
11+
mySensor.begin();
12+
mySensor.initAirQuality();
13+
//ignore first 15 readings
14+
while (count < 15) {
15+
delay(1000); //Wait 1 second
16+
mySensor.measureAirQuality();
17+
count++;
18+
}
19+
}
20+
21+
void loop() {
22+
delay(1000); //Wait 1 second
23+
mySensor.measureAirQuality();
24+
Serial.print("CO2: ");
25+
Serial.print(mySensor.CO2);
26+
Serial.print(" ppm\tTVOC");
27+
Serial.print(mySensor.TVOC);
28+
Serial.println(" ppb");
29+
mySensor.measureRawSignals();
30+
Serial.print("Raw H2: ");
31+
Serial.print(mySensor.H2);
32+
Serial.print(" \tRaw Ethanol");
33+
Serial.println(mySensor.ethanol);
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
4+
SGP30 mySensor; //create an object of the SGP30 class
5+
byte count = 0;
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
Wire.begin();
10+
Wire.setClock(400000);
11+
mySensor.begin();
12+
mySensor.getSerialID();
13+
mySensor.getFeatureSetVersion();
14+
Serial.print("SerialID: 0x");
15+
Serial.print((uint32_t)(mySensor.serialID >> 32), HEX);
16+
Serial.print((uint32_t)mySensor.serialID, HEX);
17+
Serial.print("\tFeature Set Version: 0x");
18+
Serial.print(mySensor.featureSetVersion, HEX);
19+
}
20+
21+
void loop() {
22+
23+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
4+
SGP30 mySensor; //create an object of the SGP30 class
5+
byte count = 0;
6+
bool intrpt = false;
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
Wire.begin();
11+
Wire.setClock(400000);
12+
mySensor.begin();
13+
mySensor.initAirQuality();
14+
//ignore first 15 readings
15+
while (count < 15) {
16+
delay(1000); //Wait 1 second
17+
mySensor.measureAirQuality();
18+
count++;
19+
}
20+
configureTimer1();
21+
}
22+
23+
void loop() {
24+
if (intrpt == true) {
25+
Serial.print("CO2: ");
26+
Serial.print(mySensor.CO2);
27+
Serial.print(" ppm\tTVOC");
28+
Serial.print(mySensor.TVOC);
29+
Serial.println(" ppb");
30+
intrpt = false;
31+
}
32+
}
33+
34+
void configureTimer1(void) {
35+
//https://www.instructables.com/id/Arduino-Timer-Interrupts/
36+
cli();//stop interrupts
37+
//set timer1 interrupt at 1Hz
38+
TCCR1A = 0;// set entire TCCR1A register to 0
39+
TCCR1B = 0;// same for TCCR1B
40+
TCNT1 = 0;//initialize counter value to 0
41+
// set compare match register for 1hz increments
42+
OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
43+
// turn on CTC mode
44+
TCCR1B |= (1 << WGM12);
45+
// Set CS10 and CS12 bits for 1024 prescaler
46+
TCCR1B |= (1 << CS12) | (1 << CS10);
47+
// enable timer compare interrupt
48+
TIMSK1 |= (1 << OCIE1A);
49+
sei();//allow interrupts
50+
}
51+
52+
ISR(TIMER1_COMPA_vect) {
53+
mySensor.measureAirQuality();
54+
intrpt = true;
55+
}
56+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "SparkFun_SGP30_Library.h"
2+
#include <Wire.h>
3+
4+
SGP30 mySensor; //create an object of the SGP30 class
5+
byte count = 0;
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
Wire.begin();
10+
Wire.setClock(400000);
11+
mySensor.begin();
12+
mySensor.initAirQuality();
13+
//ignore first 15 readings
14+
while (count < 15) {
15+
delay(1000); //Wait 1 second
16+
mySensor.measureAirQuality();
17+
count++;
18+
}
19+
}
20+
21+
void loop() {
22+
delay(1000); //Wait 1 second
23+
mySensor.measureAirQuality();
24+
Serial.print("CO2: ");
25+
Serial.print(mySensor.CO2);
26+
Serial.print(" ppm\tTVOC");
27+
Serial.print(mySensor.TVOC);
28+
Serial.println(" ppb");
29+
mySensor.measureRawSignals();
30+
Serial.print("Raw H2: ");
31+
Serial.print(mySensor.H2);
32+
Serial.print(" \tRaw Ethanol");
33+
Serial.println(mySensor.ethanol);
34+
}

0 commit comments

Comments
 (0)