-->
Page 1 of 1

Having difficulties running CCS811 and Si7021 in combo

PostPosted: Wed Oct 02, 2019 4:44 am
by pedens123
Hi!
I'm in the process of building a indoor climate monitor and I'm having difficulties getting the CCS811 and Si7021 sensors to run together. All the code used are the Adafruit lib examples.
I can run them separately just fine without any immediate or long run issues. However when I combine the two and start addressing both it will run fine for anywhere between 1 minute and 60 minutes, then fail with this error:
Code: Select all08:07:06.874 -> Si7021 test!
08:07:06.941 -> Found model Si7021 Rev(2) Serial #DB4AB1DE15B5FFFF
08:07:06.975 -> CO2: 0ppm, TVOC: 0ppb   Temp:25.00
08:07:07.009 -> Humidity:    58.46   Temperature: 22.24

08:36:15.081 -> CO2: 405ppm, TVOC: 0ppb   Temp:24.08
08:36:15.114 -> Humidity:    58.41   Temperature: 22.58
08:36:16.098 -> ERROR!
08:36:19.116 ->
08:36:19.116 -> Soft WDT reset
08:36:19.116 ->
08:36:19.116 -> >>>stack>>>
08:36:19.116 ->
08:36:19.116 -> ctx: cont
08:36:19.116 -> sp: 3ffffde0 end: 3fffffc0 offset: 01b0
08:36:19.150 -> 3fffff90:  00000000 00000000 00000001 3ffee4f8 
08:36:19.218 -> 3fffffa0:  3fffdad0 00000000 3ffee4c8 40202a94 
08:36:19.253 -> 3fffffb0:  feefeffe feefeffe 3ffe851c 40101021 
08:36:19.320 -> <<<stack<<<


I've experimented with various delays at the end of the loop() and between css811 and si7021 code but without any noticeable difference. Googling around for a resolution did point to issues relating to I2C clock stretching, but I haven't been able to get my head around what I need to do yet.

Any help much appreciated!

Here's the setup:
Sensor SDA is wired to GPIO4 and SCL is wired to GPIO5
NodeMCU ESP-12 development kit V1_0
Adafruit CSS811 hw and this sw lib: https://github.com/adafruit/Adafruit_Si7021 v1.0.1
Adadruit Si7021 hw and this sw lib: https://github.com/adafruit/Adafruit_CCS811 v1.2.2

Here's the code:
Code: Select all#include <Adafruit_CCS811.h>
Adafruit_CCS811 ccs;

#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();

void setup() {
  // START CCS811 example
  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);

  // START Si7021 example
  // wait for serial port to open
  while (!Serial) {
    delay(10);
  }
 
  Serial.println("Si7021 test!");
 
  if (!sensor.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    while (true)
      ;
  }

  Serial.print("Found model ");
  switch(sensor.getModel()) {
    case SI_Engineering_Samples:
      Serial.print("SI engineering samples"); break;
    case SI_7013:
      Serial.print("Si7013"); break;
    case SI_7020:
      Serial.print("Si7020"); break;
    case SI_7021:
      Serial.print("Si7021"); break;
    case SI_UNKNOWN:
    default:
      Serial.print("Unknown");
  }
  Serial.print(" Rev(");
  Serial.print(sensor.getRevision());
  Serial.print(")");
  Serial.print(" Serial #"); Serial.print(sensor.sernum_a, HEX); Serial.println(sensor.sernum_b, HEX);
}

void loop() {
  // START CCS811 example
  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);
    }
  }
 
  // START Si7021 example
  Serial.print("Humidity:    ");
  Serial.print(sensor.readHumidity(), 2);
  Serial.print("\tTemperature: ");
  Serial.println(sensor.readTemperature(), 2);
  //delay(1000); //from si7021 example
  //delay(500); // from ccs811 example
  delay(1000); // custom
 
}

Re: Having difficulties running CSS811 and Si7021 in combo

PostPosted: Wed Oct 02, 2019 5:57 pm
by davydnorris
The CSS811 needs some serious clock stretch to work - it's possible that it's then messing up the other chip on the bus.

After adding clock stretch into my code I can now run the CSS811 along with a BME280, an INA219, and a host of other chips.

BTW the value returned by the CSS811 in that screen shot is not correct - a 'null' reading is 400 and 0 so I think the clock stretch is affecting your read even in a good period

Re: Having difficulties running CSS811 and Si7021 in combo

PostPosted: Sun Oct 13, 2019 12:38 am
by pedens123
For others facing the same issue: This fixed the stability problems I was experiencing with CCS811:
This fix worked: https://github.com/arendst/Sonoff-Tasmo ... -475992268