0

CCS811 Sensor Get Raw Resistance Data
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CCS811 Sensor Get Raw Resistance Data

by jhart2020 on Thu Nov 07, 2019 4:36 pm

Hello,

I have purchased an adafruit CCS811 breakout board, and am attempting to read the raw resistance values from the sensor.

I started with the arduino CCS811 code posted below:

Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs;

void setup() {
  Serial.begin(115200);
 
  Serial.println("CCS811 Reading CO2 and VOC");
  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }
  //calibrate temperature sensor
  while(!ccs.available());
  float temp = ccs.calculateTemperature();
  ccs.setTempOffset(temp - 25.0);
  ccs.setDriveMode(4);
}

void loop() {
  if(ccs.available()){
    float temp = ccs.calculateTemperature();
    ccs.setDriveMode(4);
    ccs.readData();
   
    if(!ccs.readData()){
      ccs.readData();
      Serial.println("CO2: "+String(ccs.geteCO2())+"ppm, TVOC: "+String(ccs.getTVOC())+"ppb   Temp:"+String(temp));
      //ccs.readData();
    }
    else{
      Serial.println("Sensor read ERROR!");
      ccs.readData();
    }
  }
  delay(500);
}



This returns the eCO2 and TVOC information calculated by on board algorithm. After referencing the library for this board (https://adafruit.github.io/Adafruit_CCS ... 9af69b4338), it appears that by calling "ccs.readData()" the raw data values should be accessible for a subsequent call of "geteCO2()" or "getTVOC()" should produce those raw data values. Based on that logic, I modified the code above to:

Code: Select all | TOGGLE FULL SIZE

include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs;

void setup() {
  Serial.begin(115200);
 
 
 
  Serial.println("CCS811 Reading CO2 and VOC");
  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }
  //calibrate temperature sensor
  while(!ccs.available());
//  float temp = ccs.calculateTemperature();
//  ccs.setTempOffset(temp - 25.0);
ccs.setDriveMode(4);
}

void loop() {
  if(ccs.available()){
//    float temp = ccs.calculateTemperature();
    float temp = 3;
    if(!ccs.readData()){
      ccs.setDriveMode(4);
      ccs.readData();
      Serial.println("Resistance: "+String(ccs.geteCO2()));
    }
    else{
      Serial.println("Sensor read ERROR!");
      ccs.readData();
    }
  }
  delay(500);
}



Where I have also specified drive mode 4, as I have read that raw data cannot be accessed in drive mode 1. However, this code does not appear to change what ccs.geteCO2() produces. What am I misunderstanding about how to access the raw data values?

jhart2020
 
Posts: 1
Joined: Thu Nov 07, 2019 4:08 pm

Re: CCS811 Sensor Get Raw Resistance Data

by mikeysklar on Thu Nov 07, 2019 11:43 pm

Hello jhart2020,

I've used and really enjoyed playing with the CCS811 sensor. I'm sure you are doing something fun with it if you want to see the raw data down to the resistance readings.

Looking at the drive mode parameters I see a few constants to choose from and it would seem that you would want a high sample rate so maybe choosing CCS811_DRIVE_MODE_250MS which probably maps to 4 in the driver enumerated numbering.

Parameters
mode one of CCS811_DRIVE_MODE_IDLE, CCS811_DRIVE_MODE_1SEC, CCS811_DRIVE_MODE_10SEC, CCS811_DRIVE_MODE_60SEC, CCS811_DRIVE_MODE_250MS.


It seems like geteCO2() and getTVOC() do not necessarily read the sensor data in all cases so maybe accessing readData() directly would make more sense here?

mikeysklar
 
Posts: 346
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.