ESP8266 Air Quality Sensor CCS811

I am doing a project where I have to connect an ESP8266 NodeMcu v1 board (attached photo) and a CCS811 air quality sensor. Attached photo of the connection. Connection Photo
In arduino I have version 2.7.4 of esp8266 installed. I have installed the "Adafruit_CCS811.h" library and I am trying to run the example called "CCS811_test":

#include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs;

void setup() {
  Serial.begin(9600);

  Serial.println("CCS811 test");

  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }

  // Wait for the sensor to be ready
  while(!ccs.available());
}

void loop() {
  if(ccs.available()){
    if(!ccs.readData()){
      Serial.print("CO2: ");
      Serial.print(ccs.geteCO2());
      Serial.print("ppm, TVOC: ");
      Serial.println(ccs.getTVOC());
    }
    else{
      Serial.println("ERROR!");
      while(1);
    }
  }
  delay(500);
}

The problem is that when I open the Serial Monitor, I get "Failed to start sensor! Please check your wiring.

I think the connection is well made, so I don't know what that error might be due to.

The WAKE pin of the CCS811 should be LOW for the sensor to be active. Your picture shows that you connected it to the D3 pin of the ESP8266. But the sketch doesn’t drive LOW this pin.
I suggest:

  1. To disconnect the WAKE pin. Most CCS811 breakout boards implement a pull down resistor to keep WAKE at a LOW level when disconnected.
  2. OR: in your sketch to declare D3 as OUTPUT, and to write it LOW; this needs to be done in setup before the call to ccs.begin .
    Guy

I just tried disconnecting the WAKE PIN but I keep getting the same error "Failed to start sensor! Please check your wiring."

I really appreciate your answer, but do you have any other ideas on how to solve the problem?

Thank you so much!

There are some other points to look at, I started with an obvious one.
The CCS811 sensor has 2 possible I2C communication addresses, depending on the ADDRESS pin:
0x5A if ADDR is LOW, 0x5B if HIGH.
On the breakout board by Adafruit, the ADDR pin is pulled LOW by a pulldown resistor. The standard I2C address implemented in the Adafruit library is 0x5A.
This is not the case for all CCS811 breakout boards. E.g. I have a CCS811 breakout board by Sparkfun and there it is the opposite, ADDR is pulled HIGH by a pull-up resistor and the default address is 0x5B.
From your picture, you don’t have a regular Adafruit CCS811 breakout board, so it is possible by not connecting the ADDR pin that your board is set for an I2C address of 0x5B while the library is set for 0x5A.
There are several ways to solve this.
The most simple is to connect ADDR to GND, to force the board address to 0x5A, same as the library.
Oh, and also connect WAKE to GND, to be sure.
Guy

I just tried connecting ADDR to GND, and also WAKE to GND, but I keep getting the same error.

Okay... this gets a bit more difficult.
Time to verify that your sensor is visible for the ESP8266 on the I2C bus.
Google “arduino i2c_scanner”, you will find for sure a sketch that scans the I2C bus and reports the addresses of all devices found.
Unplug and replug the ESP8266 from your PC (to power off/on the CCS811 sensor to reset it).
Upload and run the i2c_scanner sketch.
What do you get in the serial monitor?
Guy

When running i2c_scanner I get “No I2C devices found”

PD: thank you very much for your help

Please check your connections. I have had trouble myself with loose jumpers, contact resistance between jumpers and breadboard, ...

I think the connection is good. Could the sensor be faulty?

The sensor can be faulty of course. But I have had several CCS811 (by Sparkfun) and every time I had trouble it was the connections. Do you have a multimeter? After disconnecting the USB connection, can you measure the 4 resistances between the solder joint on the NodeMCU and the corresponding solder joint on the CCS811 breakout, for 3V3, GND, SCL and SDA? We should have very low resistance in each case.

Good morning, I bought new cables and I reconnected everything, to my surprise, it already works! Thanks a lot

:slight_smile:

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