sciosense / ens16x-arduino

Arduino library for the ENS16x digital metal-oxide multi-gas sensor family
https://www.sciosense.com/ens16x-digital-metal-oxide-multi-gas-sensor-family/
MIT License
6 stars 3 forks source link

Error initialize I2C communication with ESP32 #4

Closed duckt14 closed 3 months ago

duckt14 commented 7 months ago

Hi, I’m trying to use ENS160 with ESP32 board. I need to customise the SCL and SDA pin for I2C communication because I have already different sensors connected to the board, so I used TwoWire to setting the new I2C channel. The problem is I always get this error message:

[ 165][E][Wire.cpp:526] write(): NULL TX buffer pointer [ 165][E][Wire.cpp:526] write(): NULL TX buffer pointer [ 165][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer

The code I wrote is this:


#include <ScioSense_ENS16x.h>
#include "ens16x_i2c_interface.h"

// ENS160 + AHT21 module sensor
#define I2C_SDA_ENS160 18
#define I2C_SCL_ENS160 19

TwoWire I2C_ENS160 = TwoWire(3);
I2cInterface i2c;
ENS160 ens160;

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

  I2C_ENS160.begin(I2C_SDA_ENS160, I2C_SCL_ENS160, 100000);
  i2c.begin(I2C_ENS160, 0x52);
  ens160.begin(&i2c);
  if (!ens160.begin(&i2c)) {
    Serial.println("ENS160 error!");
    while(1);
  } 
}

Regards, Enrico

starbrights commented 7 months ago

You can connect multiple device to one I2C bus as long they don't have same I2C Address.

TRScioSense commented 3 months ago

Please check your pin assignment so it fits to your selected ESP32 board; compilation with different ESP32 Dev Modules didn't cause any error message