-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample06_PressureCompensation.ino
More file actions
90 lines (66 loc) · 2.6 KB
/
Copy pathExample06_PressureCompensation.ino
File metadata and controls
90 lines (66 loc) · 2.6 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
84
85
86
87
88
89
90
/*
Example 06 - Pressure Compensation
The STCC4 assumes sea-level air pressure (101,300 Pa) by default. If you are at altitude,
or you have a barometric pressure sensor handy, writing the true ambient pressure to the
sensor improves CO2 accuracy. The value persists until overwritten or power-cycled, and
the sensor accepts 40,000 to 110,000 Pa.
(Humidity and temperature compensation need no help from you - the STCC4 reads the
onboard SHT40 by itself. Pressure is the one input it cannot sense.)
Set kAmbientPressurePa below for your location. Typical values by altitude:
Altitude (m) | Pressure (Pa)
-------------|--------------
Sea level | 101,300
500 | 95,500
1,000 | 89,900
1,564 (SFE!) | 83,900
2,000 | 79,500
3,000 | 70,100
If the pressure changes while your sketch runs (weather, or a moving platform), simply
call setPressureCompensation() again - it is accepted during measurement.
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;
// The ambient pressure at your location, in Pascals (1 hPa / mbar = 100 Pa). Defaults to sea
// level. For reference, SparkFun HQ in Boulder, Colorado sits at 1,564 m, where the pressure is
// about 83,900 Pa - set kAmbientPressurePa accordingly if you are at altitude.
const uint32_t kAmbientPressurePa = 101325;
void setup()
{
Serial.begin(115200);
Serial.println("SparkFun STCC4 Example 6 - Pressure Compensation");
Wire.begin();
while (mySensor.begin() == false)
{
Serial.println("STCC4 not connected, check your wiring!");
delay(1000);
}
Serial.println("STCC4 connected!");
// Tell the sensor the true ambient pressure before measuring.
mySensor.setPressureCompensation(kAmbientPressurePa);
Serial.print("Pressure compensation set to ");
Serial.print(kAmbientPressurePa);
Serial.println(" Pa");
mySensor.startContinuousMeasurement();
delay(1000);
Serial.println("CO2 (ppm)\tTemperature (C)\tHumidity (%RH)");
}
void loop()
{
mySensor.readMeasurement();
Serial.print(mySensor.getCO2());
Serial.print("\t\t");
Serial.print(mySensor.getTemperature(), 1);
Serial.print("\t\t");
Serial.println(mySensor.getHumidity(), 1);
delay(1000);
}