Esp8266 ccs811 i2c error

Hello,
I am currently doing a project where I try to messure the CO2 and VOC. However I always get this error:

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: application version: FFFFFFFF
18:36:18.319 -> setup: CCS811 start FAILED
18:36:18.319 -> CCS811: I2C error

I connected 3V3 with VCC, GND with GND, D1 with SCL, D2 with SDA and D3 with WAKE

This is the code I used. It is the same as Maarten Pennings code from the github CCS811 libary:
<#include <Wire.h> // 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);
}>

I also tried to switch D3 and GND and therefor edit this line: CCS811 ccs811(D3);
to CCS811 ccs811(-1);
It also doesn't work.

Does anyone knows how to solve this problem or is it even possible that the CCS811 sensor is broken? If you have further questions there is an article where the same issue got discussed:
https://github.com/maarten-pennings/CCS811/issues/7

I cannot follow your code as posted, check the forum instructions and repost the code. What you are asking does not have enough details to give an answer. However I will take a SWAG and state it appears it is a common problem with the I2C being to fast. Try this link where they slowed down the I2C clock.

#include <Wire.h> 
#include "ccs811.h"  
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);

  Wire.begin(); 

  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");


  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);

  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); 
  

  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) ); 
  }

  delay(1000); 
}

This is the code I used. It is the exact same problem as in the link from Github I posted. I tried to Ground Gnd also. Further I increased the i2cdelay to 500 however I still get this error.

In your link one of the things suggested was to run the I2C scanner, have you? Can you post a schematic, not a frizzy picture of how you have it wired and include links to technical information on all the hardware items.

Thx for answering,
I have already run the I2C scanner and it has shown, "No I2C device found".


This is how I have wired it.

I used this ESP8266 and the CJMCU-811 sensor.


There are the technical details for the CJMCU-811.

We know the problem the I2C bus in not working. Why? That is the reason for the schematic, your pretty picture does not give any details as to wiring, power, grounding, pull up, etc. Reading documentation on the I2C bus will help. Try this link for starters: I2C - SparkFun Learn Go to this section " I2C at the Hardware Level" If the scanner does not work nothing else will either.

If I understand the documentation correctly, I need pull-ups. However they are never used in any tutorial on the internet. Should I try to get some, or could it even be that the sensor is damaged?

You have it correct! Look at the internet schematics, they typically use frizzy pictures which miss lots of things, that just being one. A lot of those are produced by people that do not realy have a clue as to what is happening. They connect things, download code, it works and they are experts. You can get lucky some of the modules have pull up resistors on board, some do not, some it is an option. The value they typically use is about 10K, not really enough current but gets user in trouble when more than 4 are connected. If you look at the data sheet for the CCS811, it is 3.3V. Some but not all modules have a regulator on board, that is why I normally ask for links to technical information on the hardware items. I normally get several of any module I am going to work with, very few are bad but they all can fry. Add the pull up resistors, you can get an assortment for well under $10.00, postage probably the bigger part of the cost. Generally anything close would work so if you have 5.6K try them. Try this link: Pull Up Resistor Tutorial | AddOhms #15 - YouTube The arduino and others have pull up resistors but they are very weak, maybe 30K or more, hence my preference for external pull up/down resistors.

Thank you for the detailed answer. I will get some and try to fix the problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.