CJMCU-8128 CCS811+HDC1080+BMP280 code example

May 25, 2019

arduino | CCS811 | HDC1080 | BMP280 | sensor

A really short and simple tutorial to easily get started with the CJMCU-8128 module.

include required libraries

#include <SparkFunCCS811.h>     //Click here to get the library: http://librarymanager/All#SparkFun_CCS811
#include <SparkFunBME280.h>     //Click here to get the library: http://librarymanager/All#SparkFun_BME280
#include <ClosedCube_HDC1080.h> //Click here to get the library: http://librarymanager/All#ClosedCube_HDC1080

define sensors variable

//#define CCS811_ADDR 0x5B  //Default I2C Address
#define CCS811_ADDR 0x5A    //Alternate I2C Address

CCS811 myCCS811(CCS811_ADDR);
ClosedCube_HDC1080 myHDC1080;
BME280 myBME280;

settings for BMP280 sensor

myBME280.settings.commInterface = I2C_MODE;
myBME280.settings.I2CAddress = 0x76;
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;

myBME280.begin();

init the HDC1080 and CCS811 sensors

myHDC1080.begin(0x40);

  //It is recommended to check return status on .begin(), but it is not required.
  CCS811Core::status returnCode = myCCS811.begin();

  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    Serial.println(".begin() returned with an error.");
    while (1);      //No reason to go further
  }

here it is the complete setup function

void setup()
{
  Serial.begin(115200);
  Serial.println("CJMCU-8128 CCS811 + HDC1080 + BMP280 Example");

  myBME280.settings.commInterface = I2C_MODE;
  myBME280.settings.I2CAddress = 0x76;
  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;

  myBME280.begin();
  myHDC1080.begin(0x40);

  //It is recommended to check return status on .begin(), but it is not required.
  CCS811Core::status returnCode = myCCS811.begin();

  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    Serial.println(".begin() returned with an error.");
    while (1);      //No reason to go further
  }
}

read BMP280 sensor: preassure and altitude

    Serial.print("P[");
    Serial.print(myBME280.readFloatPressure() * 0.00750062, 2);
    Serial.print("mmHg] ");

    Serial.print("Alt[");
    Serial.print(myBME280.readFloatAltitudeMeters(), 2);
    Serial.print("m ");

read HDC1080 sensor: temperature and humidity

    Serial.print("] Temp[");
    Serial.print(myHDC1080.readTemperature());
    Serial.print("C] RH[");
    Serial.print(myHDC1080.readHumidity());

read CCS811 sensor: CO2 and TVOC

    Serial.print("%] CO2[");
    Serial.print(myCCS811.getCO2());  //Returns calculated CO2 reading
    Serial.print("] tVOC[");
    Serial.print(myCCS811.getTVOC()); //Returns calculated TVOC reading
    Serial.print("] sec[");

gist full code


comments powered by Disqus