您好,
我目前正在做一个项目,试图确定 CO2 和 VOC。但是我总是收到这个错误:
18:36:18.319 -> setup: CCS811 begin FAILED
18:36:18.319 -> setup: hardware version: FFFFFFFF
18:36:18.319 -> setup: bootloader version: FFFFFFFF
18:36:18.319 -> setup: applica
tion version: FFFFFFFF
18:36:18.319 -> setup: CCS811 start FAILED
18:36:18.319 -> CCS811: I2C error
我将 3V3 连接到 VCC,GND 连接到 GND,D1 连接到 SCL,D2 连接到 SDA 和 D3和 WAKE
这是我使用的代码。它与来自 github CCS811 库的 Maarten Pennings 代码相同:
代码:
全选#include // I2C library
#include "ccs811.h" // CCS811 library
// Wiring for ESP8266 NodeMCU boards: VDD to 3V3, GND to GND, SDA to D2, SCL to D1, nWAKE to D3 (or GND)
CCS811 ccs811(D3); // nWAKE on D3
void setup() {
// Enable serial
Serial.begin(115200);
Serial.println("");
Serial.println("setup: Starting CCS811 basic demo");
Serial.print("setup: ccs811 lib version: "); Serial.println(CCS811_VERSION);
// Enable I2C
Wire.begin();
// Enable CCS811
ccs811.set_i2cdelay(50); // Needed for ESP8266 because it doesn't handle I2C clock stretch correctly
bool ok= ccs811.begin();
if( !ok ) Serial.println("setup: CCS811 begin FAILED");
// Print CCS811 versions
Serial.print("setup: hardware version: "); Serial.println(ccs811.hardware_version(),HEX);
Serial.print("setup: bootloader version: "); Serial.println(ccs811.bootloader_version(),HEX);
Serial.print("setup: application version: "); Serial.println(ccs811.application_version(),HEX);
// Start measuring
ok= ccs811.start(CCS811_MODE_1SEC);
if( !ok ) Serial.println("setup: CCS811 start FAILED");
}
void loop() {
// Read
uint16_t eco2, etvoc, errstat, raw;
ccs811.read(&eco2,&etvoc,&errstat,&raw);
// Print measurement results based on status
if( errstat==CCS811_ERRSTAT_OK ) {
Serial.print("CCS811: ");
Serial.print("eco2="); Serial.print(eco2); Serial.print(" ppm ");
Serial.print("etvoc="); Serial.print(etvoc); Serial.print(" ppb ");
Serial.println();
} else if( errstat==CCS811_ERRSTAT_OK_NODATA ) {
Serial.println("CCS811: waiting for (new) data");
} else if( errstat & CCS811_ERRSTAT_I2CFAIL ) {
Serial.println("CCS811: I2C error");
} else {
Serial.print("CCS811: errstat="); Serial.print(errstat,HEX);
Serial.print("="); Serial.println( ccs811.errstat_str(errstat) );
}
// Wait
delay(1000);
}
我还尝试切换 D3 和 GND,因此编辑了这一行:CCS811 ccs811(D3);
到 CCS811 ccs811(-1);
它也不起作用。