Skip to content

Commit fee22e4

Browse files
committed
2 parents 994aa98 + 29f59e1 commit fee22e4

File tree

5 files changed

+289
-52
lines changed

5 files changed

+289
-52
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
Reading CO2, humidity and temperature from the SCD30
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: May 22nd, 2018
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
Feel like supporting open source hardware?
10+
Buy a board from SparkFun! https://www.sparkfun.com/products/15112
11+
12+
This example gets the SCD30's settings using the new getSettingValue function (thank you paulvha)
13+
14+
Hardware Connections:
15+
Attach RedBoard to computer using a USB cable.
16+
Connect SCD30 to RedBoard using Qwiic cable.
17+
Open Serial Monitor at 115200 baud.
18+
*/
19+
20+
#include <Wire.h>
21+
22+
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
23+
SCD30 airSensor;
24+
25+
void setup()
26+
{
27+
Serial.begin(115200);
28+
Serial.println("SCD30 Example");
29+
Wire.begin();
30+
31+
//Start sensor using the Wire port, but disable the auto-calibration
32+
if (airSensor.begin(Wire, false) == false)
33+
{
34+
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
35+
while (1)
36+
;
37+
}
38+
39+
uint16_t settingVal; // The settings will be returned in settingVal
40+
41+
if (airSensor.getForcedRecalibration(&settingVal) == true) // Get the setting
42+
{
43+
Serial.print("Forced recalibration factor (ppm) is ");
44+
Serial.println(settingVal);
45+
}
46+
else
47+
{
48+
Serial.print("getForcedRecalibration failed! Freezing...");
49+
while (1)
50+
; // Do nothing more
51+
}
52+
53+
if (airSensor.getMeasurementInterval(&settingVal) == true) // Get the setting
54+
{
55+
Serial.print("Measurement interval (s) is ");
56+
Serial.println(settingVal);
57+
}
58+
else
59+
{
60+
Serial.print("getMeasurementInterval failed! Freezing...");
61+
while (1)
62+
; // Do nothing more
63+
}
64+
65+
if (airSensor.getTemperatureOffset(&settingVal) == true) // Get the setting
66+
{
67+
Serial.print("Temperature offfset (C) is ");
68+
Serial.println(((float)settingVal) / 100.0, 2);
69+
}
70+
else
71+
{
72+
Serial.print("getTemperatureOffset failed! Freezing...");
73+
while (1)
74+
; // Do nothing more
75+
}
76+
77+
if (airSensor.getAltitudeCompensation(&settingVal) == true) // Get the setting
78+
{
79+
Serial.print("Altitude offset (m) is ");
80+
Serial.println(settingVal);
81+
}
82+
else
83+
{
84+
Serial.print("getAltitudeCompensation failed! Freezing...");
85+
while (1)
86+
; // Do nothing more
87+
}
88+
89+
if (airSensor.getFirmwareVersion(&settingVal) == true) // Get the setting
90+
{
91+
Serial.print("Firmware version is 0x");
92+
Serial.println(settingVal, HEX);
93+
}
94+
else
95+
{
96+
Serial.print("getFirmwareVersion! Freezing...");
97+
while (1)
98+
; // Do nothing more
99+
}
100+
101+
Serial.print("Auto calibration set to ");
102+
if (airSensor.getAutoSelfCalibration() == true)
103+
Serial.println("true");
104+
else
105+
Serial.println("false");
106+
107+
//The SCD30 has data ready every two seconds
108+
}
109+
110+
void loop()
111+
{
112+
if (airSensor.dataAvailable())
113+
{
114+
Serial.print("co2(ppm):");
115+
Serial.print(airSensor.getCO2());
116+
117+
Serial.print(" temp(C):");
118+
Serial.print(airSensor.getTemperature(), 1);
119+
120+
Serial.print(" humidity(%):");
121+
Serial.print(airSensor.getHumidity(), 1);
122+
123+
Serial.println();
124+
}
125+
else
126+
Serial.println("Waiting for new data");
127+
128+
delay(500);
129+
}

keywords.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ SCD30 KEYWORD1
1414

1515
SCD30 KEYWORD2
1616
begin KEYWORD2
17+
enableDebugging KEYWORD2
1718
beginMeasuring KEYWORD2
19+
StopMeasurement KEYWORD2
20+
getSettingValue KEYWORD2
21+
getForcedRecalibration KEYWORD2
22+
getMeasurementInterval KEYWORD2
23+
getTemperatureOffset KEYWORD2
24+
getAltitudeCompensation KEYWORD2
25+
getFirmwareVersion KEYWORD2
1826
getCO2 KEYWORD2
1927
getHumidity KEYWORD2
2028
getTemperature KEYWORD2
21-
getTemperatureOffset KEYWORD2
2229
setMeasurementInterval KEYWORD2
2330
setAmbientPressure KEYWORD2
2431
setAltitudeCompensation KEYWORD2
25-
getAltitudeCompensation KEYWORD2
2632
setAutoSelfCalibration KEYWORD2
27-
setTemperatureOffset KEYWORD2
2833
setForcedRecalibrationFactor KEYWORD2
34+
setTemperatureOffset KEYWORD2
35+
getAutoSelfCalibration KEYWORD2
2936
dataAvailable KEYWORD2
3037
readMeasurement KEYWORD2
31-
sendCommand KEYWORD2
38+
reset KEYWORD2
3239
sendCommand KEYWORD2
3340
readRegister KEYWORD2
3441
computeCRC8 KEYWORD2
35-
getAutoSelfCalibration KEYWORD2
36-
reset KEYWORD2
3742

3843
#######################################
3944
# Constants (LITERAL1)
@@ -48,3 +53,6 @@ COMMAND_AUTOMATIC_SELF_CALIBRATION LITERAL1
4853
COMMAND_SET_FORCED_RECALIBRATION_FACTOR LITERAL1
4954
COMMAND_SET_TEMPERATURE_OFFSET LITERAL1
5055
COMMAND_SET_ALTITUDE_COMPENSATION LITERAL1
56+
COMMAND_RESET LITERAL1
57+
COMMAND_STOP_MEAS LITERAL1
58+
COMMAND_READ_FW_VER LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun SCD30 Arduino Library
2-
version=1.0.10
2+
version=1.0.11
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the Sensirion SCD30 CO2 Sensor

0 commit comments

Comments
 (0)