Skip to content

Commit 26995c0

Browse files
committed
Update examples. Ready for test
1 parent 99658c7 commit 26995c0

File tree

14 files changed

+613
-360
lines changed

14 files changed

+613
-360
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ SCD4x mySensor;
2626
void setup()
2727
{
2828
Serial.begin(115200);
29-
Serial.println("SCD4x Example");
29+
Serial.println(F("SCD4x Example"));
3030
Wire.begin();
3131

3232
mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial
3333

3434
//.begin will start periodic measurements for us (see the later examples for details on how to overrride this)
3535
if (mySensor.begin() == false)
3636
{
37-
Serial.println("Sensor not detected. Please check wiring. Freezing...");
37+
Serial.println(F("Sensor not detected. Please check wiring. Freezing..."));
3838
while (1)
3939
;
4040
}
@@ -44,23 +44,23 @@ void setup()
4444

4545
void loop()
4646
{
47-
if (mySensor.getDataReadyStatus()) // getDataReadyStatus will return true when fresh data is available
47+
if (mySensor.readMeasurement()) // readMeasurement will return true when fresh data is available
4848
{
4949
Serial.println();
5050

51-
Serial.print("CO2(ppm):");
51+
Serial.print(F("CO2(ppm):"));
5252
Serial.print(mySensor.getCO2());
5353

54-
Serial.print("\tTemperature(C):");
54+
Serial.print(F("\tTemperature(C):"));
5555
Serial.print(mySensor.getTemperature(), 1);
5656

57-
Serial.print("\tHumidity(%RH):");
57+
Serial.print(F("\tHumidity(%RH):"));
5858
Serial.print(mySensor.getHumidity(), 1);
5959

6060
Serial.println();
6161
}
6262
else
63-
Serial.print(".");
63+
Serial.print(F("."));
6464

6565
delay(500);
6666
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Reading CO2, humidity and temperature from the SCD4x in Low Power mode
3+
By: Paul Clark
4+
Based on earlier code by: Nathan Seidle
5+
SparkFun Electronics
6+
Date: June 3rd, 2021
7+
License: MIT. See license file for more information but you can
8+
basically do whatever you want with this code.
9+
10+
Feel like supporting open source hardware?
11+
Buy a board from SparkFun! https://www.sparkfun.com/products/nnnnn
12+
13+
This example prints the current CO2 level, relative humidity, and temperature in C.
14+
15+
Hardware Connections:
16+
Attach RedBoard to computer using a USB cable.
17+
Connect SCD40/41 to RedBoard using Qwiic cable.
18+
Open Serial Monitor at 115200 baud.
19+
*/
20+
21+
#include <Wire.h>
22+
23+
#include "SparkFun_SCD4x_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD4x
24+
SCD4x mySensor;
25+
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
Serial.println(F("SCD4x Example"));
30+
Wire.begin();
31+
32+
mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial
33+
34+
//.begin will start periodic measurements for us (see the later examples for details on how to overrride this)
35+
if (mySensor.begin() == false)
36+
{
37+
Serial.println(F("Sensor not detected. Please check wiring. Freezing..."));
38+
while (1)
39+
;
40+
}
41+
42+
//By default, the SCD4x has data ready every five seconds.
43+
//We can enable low power operation and receive a reading every ~30 seconds
44+
45+
//But first, we need to stop periodic measurements otherwise startLowPowerPeriodicMeasurement will fail
46+
if (mySensor.stopPeriodicMeasurement() == true)
47+
{
48+
Serial.println(F("Periodic measurement is disabled!"));
49+
}
50+
51+
//Now we can enable low power periodic measurements
52+
if (mySensor.startLowPowerPeriodicMeasurement() == true)
53+
{
54+
Serial.println(F("Low power mode enabled!"));
55+
}
56+
57+
//Finally, we need to restart periodic measurements
58+
if (mySensor.startPeriodicMeasurement() == true)
59+
{
60+
Serial.println(F("Periodic measurements restarted!"));
61+
}
62+
}
63+
64+
void loop()
65+
{
66+
if (mySensor.readMeasurement()) // readMeasurement will return true when fresh data is available
67+
{
68+
Serial.println();
69+
70+
Serial.print(F("CO2(ppm):"));
71+
Serial.print(mySensor.getCO2());
72+
73+
Serial.print(F("\tTemperature(C):"));
74+
Serial.print(mySensor.getTemperature(), 1);
75+
76+
Serial.print(F("\tHumidity(%RH):"));
77+
Serial.print(mySensor.getHumidity(), 1);
78+
79+
Serial.println();
80+
}
81+
else
82+
Serial.print(F("."));
83+
84+
delay(1000);
85+
}

examples/Example2_SetOptions/Example2_SetOptions.ino

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Disable Auto Calibration
3+
By: Paul Clark
4+
Based on earlier code by: Nathan Seidle
5+
SparkFun Electronics
6+
Date: June 3rd, 2021
7+
License: MIT. See license file for more information but you can
8+
basically do whatever you want with this code.
9+
10+
Feel like supporting open source hardware?
11+
Buy a board from SparkFun! https://www.sparkfun.com/products/nnnnn
12+
13+
This example prints the current CO2 level, relative humidity, and temperature in C.
14+
15+
Hardware Connections:
16+
Attach RedBoard to computer using a USB cable.
17+
Connect SCD40/41 to RedBoard using Qwiic cable.
18+
Open Serial Monitor at 115200 baud.
19+
*/
20+
21+
#include <Wire.h>
22+
23+
#include "SparkFun_SCD4x_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD4x
24+
SCD4x mySensor;
25+
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
Serial.println(F("SCD4x Example"));
30+
Wire.begin();
31+
32+
mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial
33+
34+
//.begin has three boolean parameters:
35+
// measBegin: set to true to begin periodic measurements automatically;
36+
// set to false to leave periodic measurements disabled.
37+
// Default is true.
38+
// autoCalibrate: set to true to leave automatic calibration enabled;
39+
// set to false to disable automatic calibration.
40+
// Default is true.
41+
// skipStopPeriodicMeasurements: set to true to make .begin skip the initial call of stopPeriodicMeasurement;
42+
// set to false to make .begin stop periodic measurements before doing anything else.
43+
// Default is false.
44+
//Please see the next example for a full description of skipStopPeriodicMeasurements
45+
46+
//In this example, we call .begin and set autoCalibrate to false to disable automatic calibration
47+
if (mySensor.begin(true, false) == false)
48+
//measBegin_________/ |
49+
//autoCalibrate__________/
50+
{
51+
Serial.println(F("Sensor did not begin correctly. Please check wiring. Freezing..."));
52+
while (1)
53+
;
54+
}
55+
}
56+
57+
void loop()
58+
{
59+
if (mySensor.readMeasurement()) // readMeasurement will return true when fresh data is available
60+
{
61+
Serial.println();
62+
63+
Serial.print(F("CO2(ppm):"));
64+
Serial.print(mySensor.getCO2());
65+
66+
Serial.print(F("\tTemperature(C):"));
67+
Serial.print(mySensor.getTemperature(), 1);
68+
69+
Serial.print(F("\tHumidity(%RH):"));
70+
Serial.print(mySensor.getHumidity(), 1);
71+
72+
Serial.println();
73+
}
74+
else
75+
Serial.print(F("."));
76+
77+
delay(500);
78+
}

examples/Example3_WireOptions/Example3_WireOptions.ino

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

0 commit comments

Comments
 (0)