Adafruit is open, safely ... and shipping all orders at this time! Read more!
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: 2
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: 1054
Joined: Mon Aug 01, 2016 8:10 pm

Re: CCS811 Sensor Get Raw Resistance Data

by jhart2020 on Mon Dec 16, 2019 8:12 pm

Thank you for your reply, mikeysklar.

Although the name might imply it, readData() does not return the raw resistance. Here is a description:

"readData: read and store the sensor data. This data can be accessed with getTVOC() and geteCO2()." A direct call of readData() returns "0 if no error, error code otherwise."

Descriptions of

"getTVOC() :returns the stored total volatile organic compounds measurement. This does does not read the sensor. To do so, call readData()"

and

"geteCO2(): returns the stored estimated carbon dioxide measurement. This does does not read the sensor. To do so, call readData()"

describe how the sensor can be read. I had originally interpreted the readData() function as storing the raw resistance values which could then be accessed by calling either of the getTVOC or geteCO2 functions, but that does not appear to be working.

Does anyone know if there is a way to access the raw resistance data on the CCS811 sensor with the house adafruit code or is it necessary for me to write another program to accomplish this?

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

Re: CCS811 Sensor Get Raw Resistance Data

by mikeysklar on Mon Dec 16, 2019 9:55 pm

I don't see the code support in the Adafruit Arduino or CircuitPython drivers we are using to get the raw ADC values. That being said it is not that far off, the data sheet provides some clear guidance and there is a github project with some functional code to play with.

https://cdn-learn.adafruit.com/assets/a ... 1501602769

Looking at the data sheet there is more that needs to be done that just switching to drive mode 0x04. We also need to be reading the RAW register.

63BBFE43-1A82-4B8A-A258-355CB3DEA7C2.jpeg
63BBFE43-1A82-4B8A-A258-355CB3DEA7C2.jpeg (547.47 KiB) Viewed 315 times

7AD7FF87-CFF1-4D87-B25D-52B13FB8FC9C.jpeg
7AD7FF87-CFF1-4D87-B25D-52B13FB8FC9C.jpeg (353.55 KiB) Viewed 315 times

11DA6B4C-0C39-4E9C-9FAC-ABDB2144A1B0.jpeg
11DA6B4C-0C39-4E9C-9FAC-ABDB2144A1B0.jpeg (529.28 KiB) Viewed 315 times


You might want to take a look at this github project which has implemented some of the RAW capabilities as a reference point. If you happen to update the CircuitPython driver for RAW support that would be awesome. Let us know.

https://github.com/SuperHouse/esp-open- ... ras/ccs811

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

Please be positive and constructive with your questions and comments.