Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <Wire.h>
- #include "SparkFunCCS811.h"
- #define pSDA 2
- #define pSCL 14
- #define DATA_MAX_IDX 50
- #define MLX60914_I2C_ADDR 0x5a
- #define CSS811_I2C_ADDR 0x5b
- // Glbal objects for sensors
- CCS811 myCCS811(CSS811_I2C_ADDR);
- // Variables to save values from sensors
- long long int dtVOC[DATA_MAX_IDX] = {0};
- long long int dCO2[DATA_MAX_IDX] = {0};
- int i = 0;
- void setup(){
- Serial.begin(115200);
- Wire.begin(pSDA, pSCL);
- //This begins the CCS811 sensor and prints error status of .beginWithStatus()
- CCS811Core::CCS811_Status_e returnCode = myCCS811.beginWithStatus();
- Serial.print("CCS811 begin exited with: ");
- //Pass the error code to a function to print the results
- Serial.println(myCCS811.statusString(returnCode));
- //This sets the mode to 10 second reads, and prints returned error status.
- returnCode = myCCS811.setDriveMode(2);
- Serial.print("Mode request exited with: ");
- Serial.println(myCCS811.statusString(returnCode));
- }
- void loop(){
- if( myCCS811.dataAvailable() ){
- myCCS811.readAlgorithmResults(); //Calling this function updates the global tVOC and CO2 variables
- dCO2[i] = myCCS811.getCO2();
- dtVOC[i] = myCCS811.getTVOC();
- Serial.print("Iteration: ");
- Serial.println(i);
- Serial.print("CO2[");
- Serial.print(dCO2[i]);
- Serial.print("] -- tVOC[");
- Serial.print(dtVOC[i]);
- Serial.println("]");
- if( !(i % 50) ){
- memset(dCO2, 0, sizeof(dCO2));
- memset(dtVOC, 0, sizeof(dtVOC));
- i = 0;
- }
- i++;
- }
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement