Skip to content

Commit 83a1984

Browse files
Applied Arduino formatting and fixed pre-compiler directive
1 parent 16a8d9e commit 83a1984

File tree

7 files changed

+572
-573
lines changed

7 files changed

+572
-573
lines changed
Lines changed: 142 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/******************************************************************************
2-
BME280Compensated.ino
2+
BME280Compensated.ino
33
4-
Marshall Taylor @ SparkFun Electronics
4+
Marshall Taylor @ SparkFun Electronics
55
6-
April 4, 2017
6+
April 4, 2017
77
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
1010
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.
1313
14-
Hardware Connections (Breakoutboard to Arduino):
14+
Hardware Connections (Breakoutboard to Arduino):
1515
3.3V to 3.3V pin
1616
GND to GND pin
1717
SDA to A4
1818
SCL to A5
1919
20-
Resources:
21-
Uses Wire.h for i2c operation
20+
Resources:
21+
Uses Wire.h for i2c operation
2222
23-
Development environment specifics:
24-
Arduino IDE 1.8.1
23+
Development environment specifics:
24+
Arduino IDE 1.8.1
2525
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).
2727
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].
3030
31-
Distributed as-is; no warranty is given.
31+
Distributed as-is; no warranty is given.
3232
******************************************************************************/
3333
#include <SparkFunBME280.h>
3434
#include <SparkFunCCS811.h>
@@ -44,114 +44,114 @@ BME280 myBME280;
4444

4545
void setup()
4646
{
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+
7777

7878
}
7979
//---------------------------------------------------------------
8080
void loop()
8181
{
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
109109
}
110110

111111
//---------------------------------------------------------------
112112
void printInfoSerial()
113113
{
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");
119119

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");
124124

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");
129129

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");
133133

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");
137137

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");
141141

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");
145145

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");
149149

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(" %");
153153

154-
Serial.println();
154+
Serial.println();
155155

156156

157157
}
@@ -163,47 +163,47 @@ void printInfoSerial()
163163
//to this function to see what the output was.
164164
void printDriverError( status_t errorCode )
165165
{
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+
}
186186
}
187187

188188
//printSensorError gets, clears, then prints the errors
189189
//saved within the error register.
190190
void printSensorError()
191191
{
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+
}
209209
}

0 commit comments

Comments
 (0)