I want to connect two CCS811 sensors with ESP32 dev board. Since the sensors have fixed address, I am unable to use them simultaneously. I have read that on ESP32 multiple I2C buses can be created. While trying to follow that route I tried to modify the library but I am stuck. I can't simply pass different pins for SDA and SCL when calling ccs.begin() function. It only takes one argument and that is the sensor address (code chunk from library below):

bool Adafruit_CCS811::begin(uint8_t addr) {
  _i2caddr = addr;



  // check that the HW id is correct
  if (this->read8(CCS811_HW_ID) != CCS811_HW_ID_CODE)
    return false;

  // try to start the app
  this->write(CCS811_BOOTLOADER_APP_START, NULL, 0);

and the actual wire.begin() function is called in the _i2c_init() function which is defined in the lib as:

void Adafruit_CCS811::_i2c_init() {
#ifdef ESP8266

With my very basic knowledge of classes and object, I am unable to modify the library to make it work with 2 I2C buses. Could you please help me with this?

Link to Adafruit CCS811 library:(https://github.com/adafruit/Adafruit_CCS811/blob/master/Adafruit_CCS811.cpp)

My Code so far:

#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_CCS811.h"

Adafruit_CCS811 ccs1;
Adafruit_CCS811 ccs2;

TwoWire sen1 = TwoWire(0);
TwoWire sen2 = TwoWire(1);

void setup()

  Serial.println(F("CCS811 test"));

  if (!ccs1.begin(25, 26, 100000))
    Serial.println("CCS 1 Failed.");
    //while (1);
  } else {
    Serial.println("CCS 1 OK!");

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

void loop()
  if (ccs1.available())
    if (!ccs1.readData())
      Serial.println(" This is CSS");
      Serial.print("CO2: ");
      Serial.print("ppm, TVOC: ");
      //while (1);
  • CSS811 chip can have either address 0x5A or 0x5B depend on the logic level of ADDR pin. Read the datasheet. – hcheung Dec 18 '20 at 0:18
  • Yes the chip can but the module I am using can't. There is no ADDR pin. – Zaffresky Dec 18 '20 at 0:49
  • which module do you use then? the module will include either a pull up or a pull down resistor. Instead of using an extra I2C bus for the second sensor you could buy one which has the address pin broken out (for a clean solution) or desolder the onboard pullup/-down and control it with a gpio or hardwire it to Vcc/Gnd with a solder bridge. – Sim Son Dec 18 '20 at 5:53
  • I use this module banggood.com/…. I know I could buy another sensor but I also want to learn to use the second I2C bus on ESP32. That's why I trying to implement it this way – Zaffresky Dec 18 '20 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.