arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

Example9_AdvancedBegin.ino (2653B)


      1 /******************************************************************************
      2   Read basic CO2 and TVOCs on alternate Wire ports
      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   This shows how to begin communication with the sensor on a different Wire port.
     15   Helpful if you have platform that is a slave to a larger system and need
     16   a dedicated Wire port or if you need to talk to many sensors at the same time.
     17 
     18   A new sensor requires at 48-burn in. Once burned in a sensor requires
     19   20 minutes of run in before readings are considered good.
     20 
     21   Hardware Connections (Breakoutboard to Arduino):
     22   3.3V to 3.3V pin
     23   GND to GND pin
     24   SDA to A4
     25   SCL to A5
     26 
     27   Resources:
     28   Uses Wire.h for i2c operation
     29 
     30   Development environment specifics:
     31   Arduino IDE 1.8.1
     32 
     33   This code is released under the [MIT License](http://opensource.org/licenses/MIT).
     34 
     35   Please review the LICENSE.md file included with this example. If you have any questions
     36   or concerns with licensing, please contact techsupport@sparkfun.com.
     37 
     38   Distributed as-is; no warranty is given.
     39 ******************************************************************************/
     40 #include <Wire.h>
     41 
     42 #include "SparkFunCCS811.h"
     43 
     44 #define CCS811_ADDR 0x5B //Default I2C Address
     45 //#define CCS811_ADDR 0x5A //Alternate I2C Address
     46 
     47 CCS811 mySensor(CCS811_ADDR);
     48 
     49 void setup()
     50 {
     51   Serial.begin(115200);
     52   Serial.println("CCS811 Basic Example");
     53 
     54   Wire1.begin(); //Compilation will fail here if your hardware doesn't support additional Wire ports
     55 
     56   //This begins the CCS811 sensor and prints error status of .beginWithStatus()
     57   CCS811Core::CCS811_Status_e returnCode = mySensor.beginWithStatus(Wire1); //Pass Wire1 into the library
     58   Serial.print("CCS811 begin exited with: ");
     59   Serial.println(mySensor.statusString(returnCode));
     60 }
     61 
     62 void loop()
     63 {
     64   //Check to see if data is ready with .dataAvailable()
     65   if (mySensor.dataAvailable())
     66   {
     67     //If so, have the sensor read and calculate the results.
     68     //Get them later
     69     mySensor.readAlgorithmResults();
     70 
     71     Serial.print("CO2[");
     72     //Returns calculated CO2 reading
     73     Serial.print(mySensor.getCO2());
     74     Serial.print("] tVOC[");
     75     //Returns calculated TVOC reading
     76     Serial.print(mySensor.getTVOC());
     77     Serial.print("] millis[");
     78     //Simply the time since program start
     79     Serial.print(millis());
     80     Serial.print("]");
     81     Serial.println();
     82   }
     83 
     84   delay(10); //Don't spam the I2C bus
     85 }