How to read CCS811 sensor resistance value

I bought CSS811+BNE280 and run them on Arduino Uno.

I downloaded the source code and tried to make a little change to read tVOC and sensor resistance values.

But I have no idea how to get the value to print out and the CCS811 cpp file does not have any function to retrieve the resistance value.

Thanks very much for your advice in advance.

here is the code

#include <SparkFunCCS811.h>

#include <SparkFunBME280.h>

#include <Wire.h>

#define CCS811_ADDR 0x5B //Default I2C Address

#define PIN_NOT_WAKE 5

//Global sensor objects

CCS811 myCCS811(CCS811_ADDR);

BME280 myBME280;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

Serial.println();

Serial.println(“Apply BME280 data to CCS811 for compensation.”);

Wire.begin();

//This begins the CCS811 sensor and prints error status of .begin()

CCS811Core::status returnCode = myCCS811.begin();

if (returnCode != CCS811Core::SENSOR_SUCCESS)

{

//Pass the error code to a function to print the results

Serial.println(“Problem with CCS811”);

printDriverError( returnCode );

}

else

{

Serial.println(“CCS811 online”);

}

//For I2C, enable the following and disable the SPI section

myBME280.settings.commInterface = I2C_MODE;

myBME280.settings.I2CAddress = 0x77;

//Initialize BME280

//For I2C, enable the following and disable the SPI section

myBME280.settings.commInterface = I2C_MODE;

myBME280.settings.I2CAddress = 0x77;

myBME280.settings.runMode = 3; //Normal mode

myBME280.settings.tStandby = 0;

myBME280.settings.filter = 4;

myBME280.settings.tempOverSample = 5;

myBME280.settings.pressOverSample = 5;

myBME280.settings.humidOverSample = 5;

//Calling .begin() causes the settings to be loaded

delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.

byte id = myBME280.begin(); //Returns ID of 0x60 if successful

if (id != 0x60)

{

Serial.println(“Problem with BME280”);

}

else

{

Serial.println(“BME280 online”);

}

}

void loop() {

// put your main code here, to run repeatedly:

// put your main code here, to run repeatedly:

// Check to see if data is available

if (myCCS811.dataAvailable())

{

//Calling this function updates the global tVOC and eCO2 variables

myCCS811.readAlgorithmResults();

//printData fetches the values of tVOC and eCO2

Serial.print(" time[ms] ");

Serial.print(millis());

Serial.print(" TVOC[ppb] ");

Serial.print(myCCS811.getTVOC());

float BMEtempC = myBME280.readTempC();

float BMEhumid = myBME280.readFloatHumidity();

Serial.print(" temp

 ");

    Serial.print(BMEtempC, 1);



    Serial.print(" humidity[%] ");

    Serial.print(BMEhumid, 0);



    Serial.println();



    //This sends the temperature data to the CCS811

    myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);

  }

  else if (myCCS811.checkForStatusError())

  {

    Serial.println(myCCS811.getErrorRegister()); //Prints whatever CSS811 error flags are detected

  }

  

  delay(1000); //Wait for next reading



}



// printDriverError decodes the CCS811Core::status type and prints the

// type of error to the serial terminal.

// Save the return value of any function of type CCS811Core::status, then pass

// to this function to see what the output was.



void printDriverError( CCS811Core::status errorCode )

{

  switch ( errorCode )

  {

    case CCS811Core::SENSOR_SUCCESS:

      Serial.print("SUCCESS");

      break;

    case CCS811Core::SENSOR_ID_ERROR:

      Serial.print("ID_ERROR");

      break;

    case CCS811Core::SENSOR_I2C_ERROR:

      Serial.print("I2C_ERROR");

      break;

    case CCS811Core::SENSOR_INTERNAL_ERROR:

      Serial.print("INTERNAL_ERROR");

      break;

    case CCS811Core::SENSOR_GENERIC_ERROR:

      Serial.print("GENERIC_ERROR");

      break;

    default:

      Serial.print("Unspecified error.");

  }

}

Unfortunately that isn’t supported by the library and you’d need to code that in yourself. Page 15 of the data sheet has the address you need to read from for the CSS811 if that helps at all.

Software

As you use the sparkfun CCS811 library, the following calls are included:

set the reference-resistor value first : setRefResistance()

perform a call: readNTC() to read the values and calculate resistance and temperature

then perform the call : getResistance() to get the resistance that was calculated

Hardware

if you bought the Sparkfun Combo CSS811/BME280 you will have a hard time adding an external NTC.

if you bought the Sparkfun CCS811 board, you will find the NTC connector on the side

The Arduino version has an on-board NTC

Thanks for the kind reply.

I modified readAlgorithmResults( ) to calculate the resistance value based on the 6 and 7th byte data from ALG_RESULT_DATA as below.

CCS811Core::status CCS811::readAlgorithmResults( void )

{

uint8_t data[8];

// read all 8 bytes data

CCS811Core::status returnError = multiReadRegister(CSS811_ALG_RESULT_DATA, data, 8);

if( returnError != SENSOR_SUCCESS ) return returnError;

// Data ordered:

// co2MSB, co2LSB, tvocMSB, tvocLSB, status, ErrorID, rawData (Current, Voltage)

CO2 = ((uint16_t)data[0] << 8) | data[1];

tVOC = ((uint16_t)data[2] << 8) | data[3];

// retrieve current and voltage

Current = data[6] >> 2;

Voltage = uint16_t(uint8_t((data[6]) << 6)) << 2 | data[7];

// calculate resistance (page 15, AMS Application note AN000373)

Resist = 1.65 * float(Voltage) / (float(Current) 10230.000001);

return SENSOR_SUCCESS;

}