-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample02_LowPowerSingleShot.ino
More file actions
83 lines (64 loc) · 2.8 KB
/
Copy pathExample02_LowPowerSingleShot.ino
File metadata and controls
83 lines (64 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Example 02 - Low Power Single Shot
The STCC4 supports a low-power, on-demand "single shot" measurement mode: the sensor
sleeps (about 1 uA) between measurements and is woken only when a reading is needed.
With a 10 second sampling interval the sensor averages under 100 uA, compared to about
950 uA in continuous mode - ideal for battery-powered projects.
Each cycle this sketch:
1. Wakes the STCC4 from sleep mode.
2. Triggers a single shot measurement (takes 500 ms) and reads the result. The STCC4
reads the onboard SHT40 itself, so the measurement arrives already compensated and
includes temperature and humidity.
3. Puts the STCC4 back to sleep and waits out the rest of the interval.
Note: Keep the sampling interval between 5 and 600 seconds so the sensor's automatic
self-calibration algorithm works correctly. The first 2 single shot measurements after
the first ever power-up output a fixed bypass value of 390 ppm.
SparkFun Electronics
Date: 2026
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.
Hardware Connections:
IoT RedBoard --> STCC4
QWIIC --> QWIIC
Open the Serial Monitor at 115200 baud.
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/
*/
#include <SparkFun_STCC4.h>
SfeSTCC4ArdI2C mySensor;
// Time between measurements. The sensor sleeps for most of this interval.
const unsigned long kSamplingIntervalMs = 10000;
void setup()
{
Serial.begin(115200);
Serial.println("SparkFun STCC4 Example 2 - Low Power Single Shot");
Wire.begin();
while (mySensor.begin() == false)
{
Serial.println("STCC4 not connected, check your wiring!");
delay(1000);
}
Serial.println("STCC4 connected!");
Serial.println("CO2 (ppm)\tTemperature (C)\tHumidity (%RH)");
// Start with the sensor asleep; the loop wakes it for each measurement.
mySensor.enterSleepMode();
}
void loop()
{
// The sensor sleeps through this interval. Keep it between 5 and 600 seconds. (If your
// application needs measurements on a precise schedule, account for the ~500 ms measurement
// time yourself - for example with millis() timing instead of a plain delay.)
delay(kSamplingIntervalMs);
// Wake the STCC4, trigger one measurement (blocks for the 500 ms measurement time), read it,
// then put the sensor back to sleep. Compensation values and the self-calibration state are
// retained while asleep.
mySensor.exitSleepMode();
mySensor.measureSingleShot();
mySensor.readMeasurement();
Serial.print(mySensor.getCO2());
Serial.print("\t\t");
Serial.print(mySensor.getTemperature(), 1);
Serial.print("\t\t");
Serial.println(mySensor.getHumidity(), 1);
mySensor.enterSleepMode();
}