CCS811 wemos: Failed to start sensor

Hi all,
I connected the CCS811 sensor to an arduino nano like this:
image

and used this sketch:

//Arduino nano con scheda ethernet ENJ28J60
//SI connette al server mqtt
//usata libreria ethernet <EthernetENC.h> perchè è più leggera ho disattivato UDP: #define UIP_CONF_UDP  0 (libraries\EthernetENC-master\src\utility\uipethernet-conf.h )

#include <EthernetENC.h> //più leggera rispetto UIPEthernet
//#include <UIPEthernet.h>
#include <PubSubClient.h>   
#include "Adafruit_CCS811.h"
unsigned long mytime = 0;

byte mac[] = {0x80, 0x7D, 0x3A, 0x69, 0x20, 0x99 }; //physical mac address
byte mqtt_ip[] = {ip }; // ip in lan
const char* mqttUser = "";
const char* mqttPassword = "";

char buf[4]; // Buffer to store the sensor value
int updateInterval = 5000; // Interval in milliseconds

EthernetClient espClient;
PubSubClient client(espClient);
Adafruit_CCS811 ccs;
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("gas",mqttUser, mqttPassword)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void sensors() {

   if(ccs.available()){
    if(!ccs.readData()){
      int co2 = ccs.geteCO2();
      int tvoc = ccs.getTVOC();
      Serial.print("CO2: ");
      Serial.print(co2);
      Serial.print("ppm, TVOC: ");
      Serial.println(tvoc);
      client.publish("home-assistant/sensorgas/co2", itoa(co2, buf, 10));   //e'il sensore fumo
      client.publish("home-assistant/sensorgas/tvoc", itoa(tvoc, buf, 10));   //e'il sensore fumo
    }
    
    else{
      Serial.println("ERROR!");
      while(1);
    }
  }
    
}
 
void setup()
{
  Serial.begin(115200);
  delay(100);
  Ethernet.begin(mac,{ip },{ip },{ip }); //Ethernet.begin(mac, ip, dns, gateway);
  client.setServer(mqtt_ip, 1883);

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

  while(!ccs.available());
}
 
void loop()
{
  if (!client.connected()) {    reconnect();  }
  client.loop();
  if (millis()-mytime>updateInterval)
      { mytime=millis(); 
        sensors();
      }
}

Everything is ok.

But if I try to connect the same sensor to a wemos D1mini like this:
image

and using this code:

#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);
}
//calibrate temperature sensor
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
}
void loop() {
if(ccs.available()){
float temp = ccs.calculateTemperature();
if(!ccs.readData()){
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.print(ccs.getTVOC());
Serial.print("ppb Temp:");
Serial.println(temp);
}
else{
Serial.println("ERROR!");
while(1);
}
}
delay(500);
}

the result is: "Failed to start sensor! Please check your wiring."

If I perform a scan of the I2C bus I obtain the address of the sensor...

What could I check?

As it says: the wiring! You must connect VIN to the voltage of the I2C bus (3.3V for the Wemos) otherwise the I2C pullups don't work.

BTW, the two boards in the wiring diagrams are not the same. My comment above is based on the Adafruit board the other one might have another circuit.

sorry the sensor is different. my sensor is the first... so i connected the vcc/gnd/scl/sda/wak to 3.3/gnd/d1/d2/gnd....

And why isn't there a link to that sensor? We must know the schematics of the sensor board, otherwise we cannot help.

You are right...
This Is my wiring:

And doesn't work

There still no link to that board!

As I have no clue how the board is wired you have to check everything yourself! RESET must be pulled high and ADDR must be in a defined state (either pulled high or low, if pulled high you must adapt the code!). Some of that stuff may be done on the board but you decided to keep that a secret.

sorry but don't you see the schematics?

That's your wiring. We need the schematics of the CCS811 board you're using. Some of the stuff I mentioned in my last post might be implemented on that board but we simply don't know without the schematics. If you don't have schematics of the board you have to check that list yourself using reverse engineering or buy a documented board.

I have the same problem with this sensor and the Wemos D1 mini. I got it up and running on a Sparkfun Redboard though.

Why would you use resistors on the I2C wires? I don't use them and the sensor works fine on 3.3V.

I managed to find some schematics from one of the many vendors on aliexpress. The 4.7k resistors are also shown here:

Because internal pull-ups are often too weak. That depends a lot on the wiring used. If you have short wires you often don't need external pull-ups and many board have pull-ups on-board. Again, without the schematics of the actual board used we're all guessing. Don't buy a board you don't get schematics for or create the schematics yourself by reverse engineering (if the board is simple enough).

I found the schematic from here Downgrade to CCS811 Old Firmware v1.0.0 · Issue #49 · maarten-pennings/CCS811 · GitHub

Looks to me like they've included 10k pullups on the board.

What would happen if pull-ups were too weak? Would it be possible to diagnose this without a scope?

So you use exactly that board? The one that has a non-populated temperature sensor circuitry?
Did you find the resistor array on your board?

You may see some hints to the problem but diagnosing without a scope is almost impossible.
How long are your wires between the Arduino and the sensor breakout?

Yes. OP appears to have an identical board.

I don't really have a problem here, I'm just asking questions to have a chance to learn a bit more. I appreciate your input. I was hoping to have the longest possible cables I can get away with. I saw 50cm was indicated for I2C (depending on clock frequency I guess). Time will tell.

I'm quite happy with how this sensor works without resistors, currently with 10cm dupont cables. It reacts quickly to VOC and is stable over time, more so than the MICS 5524. I don't trust it for measurement of CO2. I have a Sensair S8 for this purpose.

I doubt that. Just because Fritzing offers that board to be used in the wiring diagram doesn't mean OP uses the same board. He probably just took the board with the same sensor on it. We haven't seen a photograph yet.

50cm may work if you don't have too much electrical noise in your environment (given you use the 100kHz standard frequency).

1 Like

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