1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <Arduino.h>
#include <Wire.h> // I2C library
#include "ccs811.h" // CCS811 library
#include "ClosedCube_HDC1080.h"
CCS811 ccs811_1;
CCS811 ccs811_2;
ClosedCube_HDC1080 HDC1080_1;
ClosedCube_HDC1080 HDC1080_2;
int SDApin;
int SCLpin = D1;
HDC1080_SerialNumber sernum;
char format[12];
bool vBootphase = true;
uint16_t eco2, etvoc, errstat, raw;
void setup() {Serial.begin(115200); while(!Serial){;}}
void loop()
{
if (vBootphase == true)
{
// Channel 1: Setup
SDApin = D2;
Wire.begin(SDApin, SCLpin);
delay(500);
// ** CCS811 **
Serial.println("");
Serial.println("*** CCS1 ***");
Serial.print("CCS :");
ccs811_1.set_i2cdelay(50);
ccs811_1.begin();
delay(500);
ccs811_1.start(CCS811_MODE_1SEC);
delay(1000);
Serial.print("setup: hardware version: "); Serial.println(ccs811_1.hardware_version(),HEX);
Serial.print("setup: bootloader version: "); Serial.println(ccs811_1.bootloader_version(),HEX);
Serial.print("setup: application version: "); Serial.println(ccs811_1.application_version(),HEX);
// HDC1080
HDC1080_1.begin(0x40);
Serial.print("Manufacturer ID=0x");
Serial.println(HDC1080_1.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(HDC1080_1.readDeviceId(), HEX); // 0x1050 ID of the device
Serial.print("Device Serial Number=");
sernum = HDC1080_1.readSerialNumber();
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
Serial.println(format);
// Channel 2: Setup
SDApin = D6;
Wire.begin(SDApin, SCLpin);
delay(500);
// ** CCS811 **
Serial.println("*** CCS2 ***");
// Print CCS811 versions
Serial.print("CCS2 :");
ccs811_2.set_i2cdelay(50);
ccs811_2.begin();
delay(500);
ccs811_2.start(CCS811_MODE_1SEC);
delay(1000);
Serial.print("setup: hardware version: "); Serial.println(ccs811_2.hardware_version(),HEX);
Serial.print("setup: bootloader version: "); Serial.println(ccs811_2.bootloader_version(),HEX);
Serial.print("setup: application version: "); Serial.println(ccs811_2.application_version(),HEX);
// HDC1080
HDC1080_2.begin(0x40);
Serial.print("Manufacturer ID=0x");
Serial.println(HDC1080_2.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(HDC1080_2.readDeviceId(), HEX); // 0x1050 ID of the device
Serial.print("Device Serial Number=");
sernum = HDC1080_2.readSerialNumber();
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
Serial.println(format);
vBootphase = false;
}
else
{
// Channel 1
SDApin = D2;
Wire.begin(SDApin, SCLpin);
delay(500);
// ** CCS811 **
Serial.print("\nSensor connected on: ");
Serial.print("SDA - ");Serial.print(SDApin); Serial.print(" | SCL - ");Serial.print(SCLpin);
Serial.print("\n");
ccs811_1.read(&eco2,&etvoc,&errstat,&raw);
delay(500);
Serial.print("ErrStat: ");Serial.print(errstat);Serial.print(" | ");Serial.println(ccs811_1.errstat_str(errstat));
if(!errstat==CCS811_ERRSTAT_OK)
{
Serial.print("CCS811-1: ");
Serial.println("Failed to read from sensor");
ccs811_1.begin();
delay(500);
ccs811_1.start(CCS811_MODE_1SEC);
}
else
{
Serial.print("CCS811-1: ");
Serial.print("eco2="); Serial.print(eco2); Serial.print(" ppm | ");
Serial.print("etvoc="); Serial.print(etvoc); Serial.print(" ppb");
Serial.print("\n");
}
// ** HDC1080 **
Serial.print("T="); Serial.print(HDC1080_1.readTemperature()); Serial.print("C");
Serial.print(", RH="); Serial.print(HDC1080_1.readHumidity()); Serial.println("%");
// Channel 2
SDApin = D6;
Wire.begin(SDApin, SCLpin);
delay(500);
// ** CCS811 **
Serial.print("Sensor connected on: ");
Serial.print("SDA - ");Serial.print(SDApin); Serial.print(" | SCL - ");Serial.print(SCLpin);
Serial.print("\n");
ccs811_2.read(&eco2,&etvoc,&errstat,&raw);
delay(500);
Serial.print("ErrStat: ");Serial.print(errstat);Serial.print(" | ");Serial.println(ccs811_2.errstat_str(errstat));
if(errstat!=CCS811_ERRSTAT_OK)
{
Serial.print("CCS811-2: ");
Serial.println("Failed to read from sensor");
ccs811_1.begin();
delay(500);
ccs811_2.start(CCS811_MODE_1SEC);
}
else
{
Serial.print("CCS811-2: ");
Serial.print("eco2="); Serial.print(eco2); Serial.print(" ppm | ");
Serial.print("etvoc="); Serial.print(etvoc); Serial.print(" ppb");
Serial.print("\n");
}
// ** HDC1080 **
Serial.print("T="); Serial.print(HDC1080_1.readTemperature()); Serial.print("C");
Serial.print(", RH="); Serial.print(HDC1080_1.readHumidity()); Serial.println("%");
delay(10000);
}
}
|