Skip to content

Commit ad70406

Browse files
authored
Merge pull request #13 from labeneator/master
support optional autocalibration on begin.
2 parents f5c42c8 + a36f09d commit ad70406

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 turns off the auto-calibrate function during .begin()
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+
//The SCD30 has data ready every two seconds
40+
}
41+
42+
void loop()
43+
{
44+
if (airSensor.dataAvailable())
45+
{
46+
Serial.print("co2(ppm):");
47+
Serial.print(airSensor.getCO2());
48+
49+
Serial.print(" temp(C):");
50+
Serial.print(airSensor.getTemperature(), 1);
51+
52+
Serial.print(" humidity(%):");
53+
Serial.print(airSensor.getHumidity(), 1);
54+
55+
Serial.println();
56+
}
57+
else
58+
Serial.println("Waiting for new data");
59+
60+
delay(500);
61+
}

src/SparkFun_SCD30_Arduino_Library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SCD30::SCD30(void)
3333
}
3434

3535
//Initialize the Serial port
36-
bool SCD30::begin(TwoWire &wirePort)
36+
bool SCD30::begin(TwoWire &wirePort, bool autoCalibrate)
3737
{
3838
_i2cPort = &wirePort; //Grab which port the user wants us to use
3939

@@ -58,7 +58,7 @@ bool SCD30::begin(TwoWire &wirePort)
5858
if (beginMeasuring() == true) //Start continuous measurements
5959
{
6060
setMeasurementInterval(2); //2 seconds between measurements
61-
setAutoSelfCalibration(true); //Enable auto-self-calibration
61+
setAutoSelfCalibration(autoCalibrate); //Enable auto-self-calibration
6262

6363
return (true);
6464
}

src/SparkFun_SCD30_Arduino_Library.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class SCD30
4949
{
5050
public:
5151
SCD30(void);
52-
53-
bool begin(TwoWire &wirePort = Wire); //By default use Wire port
52+
53+
bool begin(bool autoCalibrate) { return begin(Wire, autoCalibrate); }
54+
bool begin(TwoWire &wirePort = Wire, bool autoCalibrate=true); //By default use Wire port
5455

5556
bool beginMeasuring(uint16_t pressureOffset);
5657
bool beginMeasuring(void);

0 commit comments

Comments
 (0)