1
1
/* *****************************************************************************
2
- NTCCompensated.ino
2
+ NTCCompensated.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 an NTC thermistor to gather temperature data that is then used
12
- to compensate the CCS811. (humidity defaulted at 50%)
11
+ This example uses an NTC thermistor to gather temperature data that is then used
12
+ to compensate the CCS811. (humidity defaulted at 50%)
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
SEN-00250 (NTCLE100E3103JB0) between NTC terminals
20
20
21
- Resources:
22
- Uses Wire.h for i2c operation
21
+ Resources:
22
+ Uses Wire.h for i2c operation
23
23
24
- Development environment specifics:
25
- Arduino IDE 1.8.1
24
+ Development environment specifics:
25
+ Arduino IDE 1.8.1
26
26
27
- This code is released under the [MIT License](http://opensource.org/licenses/MIT).
27
+ This code is released under the [MIT License](http://opensource.org/licenses/MIT).
28
28
29
- Please review the LICENSE.md file included with this example. If you have any questions
30
- or concerns with licensing, please contact [email protected] .
29
+ Please review the LICENSE.md file included with this example. If you have any questions
30
+ or concerns with licensing, please contact [email protected] .
31
31
32
- Distributed as-is; no warranty is given.
32
+ Distributed as-is; no warranty is given.
33
33
******************************************************************************/
34
34
#include < SparkFunCCS811.h>
35
35
@@ -40,64 +40,64 @@ CCS811 myCCS811(CCS811_ADDR);
40
40
41
41
void setup ()
42
42
{
43
- Serial.begin (9600 );
44
- Serial.println ();
45
- Serial.println (" Apply NTC data to CCS811 for compensation." );
46
- status_t returnCode = myCCS811.begin ();
47
- Serial.print (" CCS811 begin exited with: " );
48
- printDriverError ( returnCode );
49
- Serial.println ();
50
-
51
- myCCS811.setRefResistance ( 9950 );
43
+ Serial.begin (9600 );
44
+ Serial.println ();
45
+ Serial.println (" Apply NTC data to CCS811 for compensation." );
46
+ status_t returnCode = myCCS811.begin ();
47
+ Serial.print (" CCS811 begin exited with: " );
48
+ printDriverError ( returnCode );
49
+ Serial.println ();
50
+
51
+ myCCS811.setRefResistance ( 9950 );
52
52
53
53
}
54
54
55
55
void loop ()
56
56
{
57
- if (myCCS811.dataAvailable ())
58
- {
59
- myCCS811.readAlgorithmResults (); // Calling this function updates the global tVOC and CO2 variables
60
-
61
- Serial.println (" CCS811 data:" );
62
- Serial.print (" CO2 concentration : " );
63
- Serial.print (myCCS811.getCO2 ());
64
- Serial.println (" ppm" );
65
-
66
- Serial.print (" TVOC concentration : " );
67
- Serial.print (myCCS811.getTVOC ());
68
- Serial.println (" ppb" );
69
-
70
- // .readNTC() causes the CCS811 library to gather ADC data and save value
71
- myCCS811.readNTC ();
72
- Serial.print (" Measured resistance : " );
73
- // After .readNTC() is called, .getResistance() can be called to actually
74
- // get the resistor value. This is not needed to get the temperature,
75
- // but can be useful information for debugging.
76
- //
77
- // Use the resistance value for custom thermistors, and calculate the
78
- // temperature yourself.
79
- Serial.print ( myCCS811.getResistance () );
80
- Serial.println (" ohms" );
81
-
82
- // After .readNTC() is called, .getTemperature() can be called to get
83
- // a temperature value providing that part SEN-00250 is used in the
84
- // NTC terminals. (NTCLE100E3103JB0)
85
- Serial.print (" Converted temperature : " );
86
- float readTemperature = myCCS811.getTemperature ();
87
- Serial.print ( readTemperature, 2 );
88
- Serial.println (" deg C" );
89
-
90
- // Pass the temperature back into the CCS811 to compensate
91
- myCCS811.setEnvironmentalData ( 50 , readTemperature);
92
-
93
- Serial.println ();
94
- }
95
- else if (myCCS811.checkForStatusError ())
96
- {
97
- printSensorError ();
98
- }
99
-
100
- delay (10 ); // Don't spam the I2C bus
57
+ if (myCCS811.dataAvailable ())
58
+ {
59
+ myCCS811.readAlgorithmResults (); // Calling this function updates the global tVOC and CO2 variables
60
+
61
+ Serial.println (" CCS811 data:" );
62
+ Serial.print (" CO2 concentration : " );
63
+ Serial.print (myCCS811.getCO2 ());
64
+ Serial.println (" ppm" );
65
+
66
+ Serial.print (" TVOC concentration : " );
67
+ Serial.print (myCCS811.getTVOC ());
68
+ Serial.println (" ppb" );
69
+
70
+ // .readNTC() causes the CCS811 library to gather ADC data and save value
71
+ myCCS811.readNTC ();
72
+ Serial.print (" Measured resistance : " );
73
+ // After .readNTC() is called, .getResistance() can be called to actually
74
+ // get the resistor value. This is not needed to get the temperature,
75
+ // but can be useful information for debugging.
76
+ //
77
+ // Use the resistance value for custom thermistors, and calculate the
78
+ // temperature yourself.
79
+ Serial.print ( myCCS811.getResistance () );
80
+ Serial.println (" ohms" );
81
+
82
+ // After .readNTC() is called, .getTemperature() can be called to get
83
+ // a temperature value providing that part SEN-00250 is used in the
84
+ // NTC terminals. (NTCLE100E3103JB0)
85
+ Serial.print (" Converted temperature : " );
86
+ float readTemperature = myCCS811.getTemperature ();
87
+ Serial.print ( readTemperature, 2 );
88
+ Serial.println (" deg C" );
89
+
90
+ // Pass the temperature back into the CCS811 to compensate
91
+ myCCS811.setEnvironmentalData ( 50 , readTemperature);
92
+
93
+ Serial.println ();
94
+ }
95
+ else if (myCCS811.checkForStatusError ())
96
+ {
97
+ printSensorError ();
98
+ }
99
+
100
+ delay (10 ); // Don't spam the I2C bus
101
101
}
102
102
103
103
// printDriverError decodes the status_t type and prints the
@@ -107,47 +107,47 @@ void loop()
107
107
// to this function to see what the output was.
108
108
void printDriverError ( status_t errorCode )
109
109
{
110
- switch ( errorCode )
111
- {
112
- case SENSOR_SUCCESS:
113
- Serial.print (" SUCCESS" );
114
- break ;
115
- case SENSOR_ID_ERROR:
116
- Serial.print (" ID_ERROR" );
117
- break ;
118
- case SENSOR_I2C_ERROR:
119
- Serial.print (" I2C_ERROR" );
120
- break ;
121
- case SENSOR_INTERNAL_ERROR:
122
- Serial.print (" INTERNAL_ERROR" );
123
- break ;
124
- case SENSOR_GENERIC_ERROR:
125
- Serial.print (" GENERIC_ERROR" );
126
- break ;
127
- default :
128
- Serial.print (" Unspecified error." );
129
- }
110
+ switch ( errorCode )
111
+ {
112
+ case SENSOR_SUCCESS:
113
+ Serial.print (" SUCCESS" );
114
+ break ;
115
+ case SENSOR_ID_ERROR:
116
+ Serial.print (" ID_ERROR" );
117
+ break ;
118
+ case SENSOR_I2C_ERROR:
119
+ Serial.print (" I2C_ERROR" );
120
+ break ;
121
+ case SENSOR_INTERNAL_ERROR:
122
+ Serial.print (" INTERNAL_ERROR" );
123
+ break ;
124
+ case SENSOR_GENERIC_ERROR:
125
+ Serial.print (" GENERIC_ERROR" );
126
+ break ;
127
+ default :
128
+ Serial.print (" Unspecified error." );
129
+ }
130
130
}
131
131
132
132
// printSensorError gets, clears, then prints the errors
133
133
// saved within the error register.
134
134
void printSensorError ()
135
135
{
136
- uint8_t error = myCCS811.getErrorRegister ();
137
-
138
- if ( error == 0xFF )// comm error
139
- {
140
- Serial.println (" Failed to get ERROR_ID register." );
141
- }
142
- else
143
- {
144
- Serial.print (" Error: " );
145
- if (error & 1 << 5 ) Serial.print (" HeaterSupply" );
146
- if (error & 1 << 4 ) Serial.print (" HeaterFault" );
147
- if (error & 1 << 3 ) Serial.print (" MaxResistance" );
148
- if (error & 1 << 2 ) Serial.print (" MeasModeInvalid" );
149
- if (error & 1 << 1 ) Serial.print (" ReadRegInvalid" );
150
- if (error & 1 << 0 ) Serial.print (" MsgInvalid" );
151
- Serial.println ();
152
- }
136
+ uint8_t error = myCCS811.getErrorRegister ();
137
+
138
+ if ( error == 0xFF ) // comm error
139
+ {
140
+ Serial.println (" Failed to get ERROR_ID register." );
141
+ }
142
+ else
143
+ {
144
+ Serial.print (" Error: " );
145
+ if (error & 1 << 5 ) Serial.print (" HeaterSupply" );
146
+ if (error & 1 << 4 ) Serial.print (" HeaterFault" );
147
+ if (error & 1 << 3 ) Serial.print (" MaxResistance" );
148
+ if (error & 1 << 2 ) Serial.print (" MeasModeInvalid" );
149
+ if (error & 1 << 1 ) Serial.print (" ReadRegInvalid" );
150
+ if (error & 1 << 0 ) Serial.print (" MsgInvalid" );
151
+ Serial.println ();
152
+ }
153
153
}
0 commit comments