maarten-pennings / CCS811

Arduino library for the CCS811 gas sensor for monitoring indoor air quality.
MIT License
165 stars 46 forks source link

Wire.xxxx in library #19

Open michapr opened 5 years ago

michapr commented 5 years ago

Hi, how to use the lib with an ESP32 (as sample) with two I2C interfaces?

Because of using the predefined Wire functions it is not possible to redefine the interface.

bool CCS811::i2cwrite(int regaddr, int count, const uint8_t * buf) {
Wire.beginTransmission(_slaveaddr);              // START, SLAVEADDR
Wire.write(regaddr); // Register address

Using following code (as sample) - it will not work:

TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);
...
I2Cone.begin(SDA1,SCL1,400000); // SDA pin 21, SCL pin 22 
I2Ctwo.begin(SDA2,SCL2,400000); // SDA pin 5, SCL pin 4 builtin OLED
...

As sample in CCS811Core was realized better:

CCS811Core::status CCS811Core::beginCore(TwoWire &wirePort)
{
    CCS811Core::status returnError = SENSOR_SUCCESS;

    _i2cPort = &wirePort; //Pull in user's choice of I2C hardware

    //Wire.begin(); //See issue 13 https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library/issues/13
...

Maybe you could adapt it?

Thanks!

maarten-pennings commented 4 years ago

Like the idea, did not yet have the time.