Skip to content

Instantly share code, notes, and snippets.

@mindeon
Created March 22, 2019 21:25
Show Gist options
  • Save mindeon/842428d6dcdceb984b97e2bda78eaf16 to your computer and use it in GitHub Desktop.
Save mindeon/842428d6dcdceb984b97e2bda78eaf16 to your computer and use it in GitHub Desktop.
CJMCU-8128 CCS811 + HDC1080 + BMP280 (banggood.com) code example
//CJMCU-8128 CCS811 + HDC1080 + BMP280 (banggood.com)
#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 CCS811_ADDR 0x5B //Default I2C Address
#define CCS811_ADDR 0x5A //Alternate I2C Address
CCS811 myCCS811(CCS811_ADDR);
ClosedCube_HDC1080 myHDC1080;
BME280 myBME280;
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
}
}
void loop()
{
//Check if data is ready
if (myCCS811.dataAvailable())
{
//If so, have the sensor read and calculate the results.
//Get them later
myCCS811.readAlgorithmResults();
// Serial.println("BME280 data:");
// Serial.print(" Temperature: ");
// Serial.print(myBME280.readTempC(), 2);
// Serial.println(" degrees C");
Serial.print("P[");
Serial.print(myBME280.readFloatPressure() * 0.00750062, 2);
Serial.print("mmHg] ");
Serial.print("Alt[");
Serial.print(myBME280.readFloatAltitudeMeters(), 2);
Serial.print("m ");
// Serial.print(" %RH: ");
// Serial.print(myBME280.readFloatHumidity(), 2);
// Serial.println(" %");
Serial.print("] Temp[");
Serial.print(myHDC1080.readTemperature());
Serial.print("C] RH[");
Serial.print(myHDC1080.readHumidity());
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[");
Serial.print(millis()/1000); //seconds since start
Serial.print("]");
Serial.println();
//compensating the CCS811 with humidity and temperature readings from the HDC1080
myCCS811.setEnvironmentalData(myHDC1080.readHumidity(), myHDC1080.readTemperature());
}
delay(10); //Don't spam the I2C bus
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment