Readings8118.ino (1946B)
1 /****************************************************************************** 2 Read basic CO2 and TVOCs 3 4 Marshall Taylor @ SparkFun Electronics 5 Nathan Seidle @ SparkFun Electronics 6 7 April 4, 2017 8 9 https://github.com/sparkfun/CCS811_Air_Quality_Breakout 10 https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library 11 12 Read the TVOC and CO2 values from the SparkFun CSS811 breakout board 13 14 A new sensor requires at 48-burn in. Once burned in a sensor requires 15 20 minutes of run in before readings are considered good. 16 17 Hardware Connections (Breakoutboard to Arduino): 18 3.3V to 3.3V pin 19 GND to GND pin 20 SDA to A4 21 SCL to A5 22 23 ******************************************************************************/ 24 #include <Wire.h> 25 26 #include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811 27 28 //#define CCS811_ADDR 0x5B //Default I2C Address 29 #define CCS811_ADDR 0x5A //Alternate I2C Address 30 31 CCS811 mySensor(CCS811_ADDR); 32 33 void setup() 34 { 35 Serial.begin(115200); 36 Serial.println("CCS811 Basic Example"); 37 38 Wire.begin(); //Inialize I2C Hardware 39 40 if (mySensor.begin() == false) 41 { 42 Serial.print("CCS811 error. Please check wiring. Freezing..."); 43 while (1) 44 ; 45 } 46 } 47 48 void loop() 49 { 50 //Check to see if data is ready with .dataAvailable() 51 if (mySensor.dataAvailable()) 52 { 53 //If so, have the sensor read and calculate the results. 54 //Get them later 55 mySensor.readAlgorithmResults(); 56 57 Serial.print("CO2["); 58 //Returns calculated CO2 reading 59 Serial.print(mySensor.getCO2()); 60 Serial.print("] tVOC["); 61 //Returns calculated TVOC reading 62 Serial.print(mySensor.getTVOC()); 63 Serial.print("] millis["); 64 //Display the time since program start 65 Serial.print(millis()); 66 Serial.print("]"); 67 Serial.print(mySensor.getTemperature()); 68 Serial.print(mySensor.getResistance()); 69 Serial.println(); 70 } 71 72 delay(10); //Don't spam the I2C bus 73 }