1
1
/* *****************************************************************************
2
- BME280Compensated.ino
2
+ BME280Compensated.ino
3
3
4
- Marshall Taylor @ SparkFun Electronics
4
+ Marshall Taylor @ SparkFun Electronics
5
5
6
- April 4, 2017
6
+ April 4, 2017
7
7
8
- https://github.com/sparkfun/CCS811_Air_Quality_Breakout
9
- https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library
8
+ https://github.com/sparkfun/CCS811_Air_Quality_Breakout
9
+ https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library
10
10
11
- This example uses a BME280 to gather environmental data that is then used
12
- to compensate the CCS811.
11
+ This example uses a BME280 to gather environmental data that is then used
12
+ to compensate the CCS811.
13
13
14
- Hardware Connections (Breakoutboard to Arduino):
14
+ Hardware Connections (Breakoutboard to Arduino):
15
15
3.3V to 3.3V pin
16
16
GND to GND pin
17
17
SDA to A4
18
18
SCL to A5
19
19
20
- Resources:
21
- Uses Wire.h for i2c operation
20
+ Resources:
21
+ Uses Wire.h for i2c operation
22
22
23
- Development environment specifics:
24
- Arduino IDE 1.8.1
23
+ Development environment specifics:
24
+ Arduino IDE 1.8.1
25
25
26
- This code is released under the [MIT License](http://opensource.org/licenses/MIT).
26
+ This code is released under the [MIT License](http://opensource.org/licenses/MIT).
27
27
28
- Please review the LICENSE.md file included with this example. If you have any questions
29
- or concerns with licensing, please contact [email protected] .
28
+ Please review the LICENSE.md file included with this example. If you have any questions
29
+ or concerns with licensing, please contact [email protected] .
30
30
31
- Distributed as-is; no warranty is given.
31
+ Distributed as-is; no warranty is given.
32
32
******************************************************************************/
33
33
#include < SparkFunBME280.h>
34
34
#include < SparkFunCCS811.h>
@@ -44,114 +44,114 @@ BME280 myBME280;
44
44
45
45
void setup ()
46
46
{
47
- Serial.begin (9600 );
48
- Serial.println ();
49
- Serial.println (" Apply BME280 data to CCS811 for compensation." );
50
-
51
- // This begins the CCS811 sensor and prints error status of .begin()
52
- status_t returnCode = myCCS811.begin ();
53
- Serial.print (" CCS811 begin exited with: " );
54
- // Pass the error code to a function to print the results
55
- printDriverError ( returnCode );
56
- Serial.println ();
57
-
58
- // For I2C, enable the following and disable the SPI section
59
- myBME280.settings .commInterface = I2C_MODE;
60
- myBME280.settings .I2CAddress = 0x77 ;
61
-
62
- // Initialize BME280
63
- // For I2C, enable the following and disable the SPI section
64
- myBME280.settings .commInterface = I2C_MODE;
65
- myBME280.settings .I2CAddress = 0x77 ;
66
- myBME280.settings .runMode = 3 ; // Normal mode
67
- myBME280.settings .tStandby = 0 ;
68
- myBME280.settings .filter = 4 ;
69
- myBME280.settings .tempOverSample = 5 ;
70
- myBME280.settings .pressOverSample = 5 ;
71
- myBME280.settings .humidOverSample = 5 ;
72
-
73
- // Calling .begin() causes the settings to be loaded
74
- delay (10 ); // Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
75
- myBME280.begin ();
76
-
47
+ Serial.begin (9600 );
48
+ Serial.println ();
49
+ Serial.println (" Apply BME280 data to CCS811 for compensation." );
50
+
51
+ // This begins the CCS811 sensor and prints error status of .begin()
52
+ status_t returnCode = myCCS811.begin ();
53
+ Serial.print (" CCS811 begin exited with: " );
54
+ // Pass the error code to a function to print the results
55
+ printDriverError ( returnCode );
56
+ Serial.println ();
57
+
58
+ // For I2C, enable the following and disable the SPI section
59
+ myBME280.settings .commInterface = I2C_MODE;
60
+ myBME280.settings .I2CAddress = 0x77 ;
61
+
62
+ // Initialize BME280
63
+ // For I2C, enable the following and disable the SPI section
64
+ myBME280.settings .commInterface = I2C_MODE;
65
+ myBME280.settings .I2CAddress = 0x77 ;
66
+ myBME280.settings .runMode = 3 ; // Normal mode
67
+ myBME280.settings .tStandby = 0 ;
68
+ myBME280.settings .filter = 4 ;
69
+ myBME280.settings .tempOverSample = 5 ;
70
+ myBME280.settings .pressOverSample = 5 ;
71
+ myBME280.settings .humidOverSample = 5 ;
72
+
73
+ // Calling .begin() causes the settings to be loaded
74
+ delay (10 ); // Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
75
+ myBME280.begin ();
76
+
77
77
78
78
}
79
79
// ---------------------------------------------------------------
80
80
void loop ()
81
81
{
82
- // Check to see if data is available
83
- if (myCCS811.dataAvailable ())
84
- {
85
- // Calling this function updates the global tVOC and eCO2 variables
86
- myCCS811.readAlgorithmResults ();
87
- // printInfoSerial fetches the values of tVOC and eCO2
88
- printInfoSerial ();
89
-
90
- float BMEtempC = myBME280.readTempC ();
91
- float BMEhumid = myBME280.readFloatHumidity ();
92
-
93
- Serial.print (" Applying new values (deg C, %): " );
94
- Serial.print (BMEtempC);
95
- Serial.print (" ," );
96
- Serial.println (BMEhumid);
97
- Serial.println ();
98
-
99
- // This sends the temperature data to the CCS811
100
- myCCS811.setEnvironmentalData (BMEhumid, BMEtempC);
101
- }
102
- else if (myCCS811.checkForStatusError ())
103
- {
104
- // If the CCS811 found an internal error, print it.
105
- printSensorError ();
106
- }
107
-
108
- delay (2000 ); // Wait for next reading
82
+ // Check to see if data is available
83
+ if (myCCS811.dataAvailable ())
84
+ {
85
+ // Calling this function updates the global tVOC and eCO2 variables
86
+ myCCS811.readAlgorithmResults ();
87
+ // printInfoSerial fetches the values of tVOC and eCO2
88
+ printInfoSerial ();
89
+
90
+ float BMEtempC = myBME280.readTempC ();
91
+ float BMEhumid = myBME280.readFloatHumidity ();
92
+
93
+ Serial.print (" Applying new values (deg C, %): " );
94
+ Serial.print (BMEtempC);
95
+ Serial.print (" ," );
96
+ Serial.println (BMEhumid);
97
+ Serial.println ();
98
+
99
+ // This sends the temperature data to the CCS811
100
+ myCCS811.setEnvironmentalData (BMEhumid, BMEtempC);
101
+ }
102
+ else if (myCCS811.checkForStatusError ())
103
+ {
104
+ // If the CCS811 found an internal error, print it.
105
+ printSensorError ();
106
+ }
107
+
108
+ delay (2000 ); // Wait for next reading
109
109
}
110
110
111
111
// ---------------------------------------------------------------
112
112
void printInfoSerial ()
113
113
{
114
- // getCO2() gets the previously read data from the library
115
- Serial.println (" CCS811 data:" );
116
- Serial.print (" CO2 concentration : " );
117
- Serial.print (myCCS811.getCO2 ());
118
- Serial.println (" ppm" );
114
+ // getCO2() gets the previously read data from the library
115
+ Serial.println (" CCS811 data:" );
116
+ Serial.print (" CO2 concentration : " );
117
+ Serial.print (myCCS811.getCO2 ());
118
+ Serial.println (" ppm" );
119
119
120
- // getTVOC() gets the previously read data from the library
121
- Serial.print (" TVOC concentration : " );
122
- Serial.print (myCCS811.getTVOC ());
123
- Serial.println (" ppb" );
120
+ // getTVOC() gets the previously read data from the library
121
+ Serial.print (" TVOC concentration : " );
122
+ Serial.print (myCCS811.getTVOC ());
123
+ Serial.println (" ppb" );
124
124
125
- Serial.println (" BME280 data:" );
126
- Serial.print (" Temperature: " );
127
- Serial.print (myBME280.readTempC (), 2 );
128
- Serial.println (" degrees C" );
125
+ Serial.println (" BME280 data:" );
126
+ Serial.print (" Temperature: " );
127
+ Serial.print (myBME280.readTempC (), 2 );
128
+ Serial.println (" degrees C" );
129
129
130
- Serial.print (" Temperature: " );
131
- Serial.print (myBME280.readTempF (), 2 );
132
- Serial.println (" degrees F" );
130
+ Serial.print (" Temperature: " );
131
+ Serial.print (myBME280.readTempF (), 2 );
132
+ Serial.println (" degrees F" );
133
133
134
- Serial.print (" Pressure: " );
135
- Serial.print (myBME280.readFloatPressure (), 2 );
136
- Serial.println (" Pa" );
134
+ Serial.print (" Pressure: " );
135
+ Serial.print (myBME280.readFloatPressure (), 2 );
136
+ Serial.println (" Pa" );
137
137
138
- Serial.print (" Pressure: " );
139
- Serial.print ((myBME280.readFloatPressure () * 0.0002953 ), 2 );
140
- Serial.println (" InHg" );
138
+ Serial.print (" Pressure: " );
139
+ Serial.print ((myBME280.readFloatPressure () * 0.0002953 ), 2 );
140
+ Serial.println (" InHg" );
141
141
142
- Serial.print (" Altitude: " );
143
- Serial.print (myBME280.readFloatAltitudeMeters (), 2 );
144
- Serial.println (" m" );
142
+ Serial.print (" Altitude: " );
143
+ Serial.print (myBME280.readFloatAltitudeMeters (), 2 );
144
+ Serial.println (" m" );
145
145
146
- Serial.print (" Altitude: " );
147
- Serial.print (myBME280.readFloatAltitudeFeet (), 2 );
148
- Serial.println (" ft" );
146
+ Serial.print (" Altitude: " );
147
+ Serial.print (myBME280.readFloatAltitudeFeet (), 2 );
148
+ Serial.println (" ft" );
149
149
150
- Serial.print (" %RH: " );
151
- Serial.print (myBME280.readFloatHumidity (), 2 );
152
- Serial.println (" %" );
150
+ Serial.print (" %RH: " );
151
+ Serial.print (myBME280.readFloatHumidity (), 2 );
152
+ Serial.println (" %" );
153
153
154
- Serial.println ();
154
+ Serial.println ();
155
155
156
156
157
157
}
@@ -163,47 +163,47 @@ void printInfoSerial()
163
163
// to this function to see what the output was.
164
164
void printDriverError ( status_t errorCode )
165
165
{
166
- switch ( errorCode )
167
- {
168
- case SENSOR_SUCCESS:
169
- Serial.print (" SUCCESS" );
170
- break ;
171
- case SENSOR_ID_ERROR:
172
- Serial.print (" ID_ERROR" );
173
- break ;
174
- case SENSOR_I2C_ERROR:
175
- Serial.print (" I2C_ERROR" );
176
- break ;
177
- case SENSOR_INTERNAL_ERROR:
178
- Serial.print (" INTERNAL_ERROR" );
179
- break ;
180
- case SENSOR_GENERIC_ERROR:
181
- Serial.print (" GENERIC_ERROR" );
182
- break ;
183
- default :
184
- Serial.print (" Unspecified error." );
185
- }
166
+ switch ( errorCode )
167
+ {
168
+ case SENSOR_SUCCESS:
169
+ Serial.print (" SUCCESS" );
170
+ break ;
171
+ case SENSOR_ID_ERROR:
172
+ Serial.print (" ID_ERROR" );
173
+ break ;
174
+ case SENSOR_I2C_ERROR:
175
+ Serial.print (" I2C_ERROR" );
176
+ break ;
177
+ case SENSOR_INTERNAL_ERROR:
178
+ Serial.print (" INTERNAL_ERROR" );
179
+ break ;
180
+ case SENSOR_GENERIC_ERROR:
181
+ Serial.print (" GENERIC_ERROR" );
182
+ break ;
183
+ default :
184
+ Serial.print (" Unspecified error." );
185
+ }
186
186
}
187
187
188
188
// printSensorError gets, clears, then prints the errors
189
189
// saved within the error register.
190
190
void printSensorError ()
191
191
{
192
- uint8_t error = myCCS811.getErrorRegister ();
193
-
194
- if ( error == 0xFF )// comm error
195
- {
196
- Serial.println (" Failed to get ERROR_ID register." );
197
- }
198
- else
199
- {
200
- Serial.print (" Error: " );
201
- if (error & 1 << 5 ) Serial.print (" HeaterSupply" );
202
- if (error & 1 << 4 ) Serial.print (" HeaterFault" );
203
- if (error & 1 << 3 ) Serial.print (" MaxResistance" );
204
- if (error & 1 << 2 ) Serial.print (" MeasModeInvalid" );
205
- if (error & 1 << 1 ) Serial.print (" ReadRegInvalid" );
206
- if (error & 1 << 0 ) Serial.print (" MsgInvalid" );
207
- Serial.println ();
208
- }
192
+ uint8_t error = myCCS811.getErrorRegister ();
193
+
194
+ if ( error == 0xFF ) // comm error
195
+ {
196
+ Serial.println (" Failed to get ERROR_ID register." );
197
+ }
198
+ else
199
+ {
200
+ Serial.print (" Error: " );
201
+ if (error & 1 << 5 ) Serial.print (" HeaterSupply" );
202
+ if (error & 1 << 4 ) Serial.print (" HeaterFault" );
203
+ if (error & 1 << 3 ) Serial.print (" MaxResistance" );
204
+ if (error & 1 << 2 ) Serial.print (" MeasModeInvalid" );
205
+ if (error & 1 << 1 ) Serial.print (" ReadRegInvalid" );
206
+ if (error & 1 << 0 ) Serial.print (" MsgInvalid" );
207
+ Serial.println ();
208
+ }
209
209
}
0 commit comments