Issu with TCA9548A I2C multiplexer and ABP2 pressure sensor

Hello everybody
I am trying to operate a pressure sensor (abp2 from Honeywell) behind an I2C multiplexer (TCA9548). The pressure sensor connected directly on I2C interface work great. I also also try another model of sensor (SHT31 temperature sensor) behind the multiplexer and work fine too.
But if I connect the ABP2 behind the multiplexer, the pressure sensor does not respond.
It is as if the order did not pass through the multiplexer but only for this sensor.

Do you have any ideas ?
(I try to put some code here soon)

//This is the function to read SHT31 sensor
void ReadSht (uint8_t Address, float *humidity, float *temperature)
{
  	sht.begin(Address);
    delay(5);
    sht.read();
    delay(5);
    *humidity=sht.getHumidity();
    *temperature=sht.getTemperature();
}

//This is the function to read ABP2 sensor (directly from ABP2 datasheet)
void ReadAbp2 (uint8_t Address, double *pressure, double *temperature)
{
uint8_t data[7]; // holds output data
double press_counts = 0; // digital pressure reading [counts]
double temp_counts = 0; // digital temperature reading [counts]
double outputmax =15099494; //15099494; //16777215 output at maximum pressure [counts]
double outputmin =1677722; //1677722; //0// output at minimum pressure [counts]
double pmax = 60; // maximum value of pressure range [bar, psi, kPa, etc.]
double pmin = 0; // minimum value of pressure range [bar, psi, kPa, etc.]
double percentage = 0; // holds percentage of full scale data
char  printBuffer[200], cBuff[20], percBuff[20], pBuff[20], tBuff[20];
uint8_t cmd[3] = {0xAA, 0x00, 0x00}; // command to be sent
int i = 0;

 Wire.beginTransmission(Address);
int stat = Wire.write (cmd, 3); // write command to the sensor
 stat |= Wire.endTransmission();
 delay(10); //
 Wire.requestFrom(Address, 7); // read back Sensor data 7 bytes
 
 for (i = 0; i < 7; i++) {
 data [i] = Wire.read();
 }
 press_counts = data[3] + data[2] * 256 + data[1] * 65536; // calculate digital pressure counts
 temp_counts = data[6] + data[5] * 256 + data[4] * 65536; // calculate digital temperature counts
 *temperature = (temp_counts * 200 / 16777215) - 50; // calculate temperature in deg c
 percentage = (press_counts / 16777215) * 100; // calculate pressure as percentage of full scale
 //calculation of pressure value according to equation 2 of datasheet
 *pressure = (((press_counts - outputmin) * (pmax - pmin)) / (outputmax - outputmin) + pmin)-0.21;
 
 
 
 //this is code to use TCA9548 multiplexer :
 #include "TCA9548A.h"
 #include "SHT85.h"
 #include <Wire.h>
#define SHT85_ADDRESS   0x44
#define SERIAL Serial
  #define WIRE Wire
  TCA9548A<TwoWire> TCA;


SHT85 sht;
int channels[8]={TCA_CHANNEL_0,TCA_CHANNEL_1,TCA_CHANNEL_2,TCA_CHANNEL_3,TCA_CHANNEL_4,TCA_CHANNEL_5,TCA_CHANNEL_6,TCA_CHANNEL_7};

void setup()
{
  Serial.begin(115200);
  while(!SERIAL){};
   TCA.begin(WIRE);
  //defaut all channel was closed
  //TCA.openAll();
  //TCA.closeAll();
}


//this code work with 2 sensor SHT31 connected on Two output of multiplexer (Channel 0 and Channel 1)
void loop()
{
TCA.openChannel(TCA_CHANNEL_0);
ReadSht(SHT85_ADDRESS,&hum1,&temp1);
Serial.print("SHT0 : ");
Serial.print(hum1);
Serial.print(";");
Serial.print(temp1);
Serial.println("");
TCA.closeChannel(TCA_CHANNEL_0);
	
TCA.openChannel(TCA_CHANNEL_1);
ReadSht(SHT85_ADDRESS,&hum1,&temp1);
Serial.print("SHT1 : ");
Serial.print(hum1);
Serial.print(";");
Serial.print(temp1);
Serial.println("");
TCA.closeChannel(TCA_CHANNEL_1);
}


//this code is OK with ABP2 directly connected on I2C line
void loop()
{
ReadAbp2(id,&abppress1,&abptemp1);
Serial.print("Abp2 : ");
Serial.print(abppress1);
Serial.print(";");
Serial.print(abptemp1);
Serial.println("");
}

//this code not working (no response of ABP2 sensor) but if i connected it dirctly on I2C channel it works...
void loop()
{
TCA.openChannel(TCA_CHANNEL_0);
ReadAbp2(id,&abppress1,&abptemp1);
Serial.print("Abp2 : ");
Serial.print(abppress1);
Serial.print(";");
Serial.print(abptemp1);
Serial.println("");
TCA.closeChannel(TCA_CHANNEL_0);
}

You should enable just the channel where the sensor is connected.

I already do that (you can see this exemple in the code)

With this code, Sensor don't communicate (but if i connect it directly on the I2C line instead of channel 0 multiplexer, i have value). it is as if the reading code of the sensor inhibited the multiplexer :

//this code not working (no response of ABP2 sensor) but if i connected it dirctly on I2C channel it works...
void loop()
{
TCA.openChannel(TCA_CHANNEL_0);
ReadAbp2(id,&abppress1,&abptemp1);
Serial.print("Abp2 : ");
Serial.print(abppress1);
Serial.print(";");
Serial.print(abptemp1);
Serial.println("");
TCA.closeChannel(TCA_CHANNEL_0);
}```

Obviously you don't else you would get a result.

Which are the addresses of all your devices, including mux?

please post a complete sketch. Your snippets do not include any variable declarations or values.

Library for TCA is Grove_8Channel_I2C_Hub from seed studio

#include "TCA9548A.h"

#include "SHT85.h"
#include <Wire.h>

#define SHT85_ADDRESS   0x44 //SHT31 I2C Adress

uint8_t id = 0x28; // i2c address for ABBP2 Sensor

#define WIRE Wire

#define SERIAL Serial

TCA9548A<TwoWire> TCA;  //mux adress directly on librarie = 0x70

SHT85 sht;

int channels[8]={TCA_CHANNEL_0,TCA_CHANNEL_1,TCA_CHANNEL_2,TCA_CHANNEL_3,TCA_CHANNEL_4,TCA_CHANNEL_5,TCA_CHANNEL_6,TCA_CHANNEL_7};

float hum1;  //Stores humidity value
float temp1; //Stores temp

double abppress1;  
double abptemp1;  

void setup()
{
  Serial.begin(115200);
  while(!SERIAL){};
  
  TCA.begin(WIRE);
}

void ReadSht (uint8_t Address, float *humidity, float *temperature)
{
  	sht.begin(Address);
    delay(5);
    sht.read();
    delay(5);
    *humidity=sht.getHumidity();
    *temperature=sht.getTemperature();
}

void ReadAbp2 (uint8_t Address, double *pressure, double *temperature)
{
uint8_t data[7]; // holds output data
double press_counts = 0; // digital pressure reading [counts]
double temp_counts = 0; // digital temperature reading [counts]
double outputmax =15099494; //15099494; //16777215 output at maximum pressure [counts]
double outputmin =1677722; //1677722; //0// output at minimum pressure [counts]
double pmax = 60; // maximum value of pressure range [bar, psi, kPa, etc.]
double pmin = 0; // minimum value of pressure range [bar, psi, kPa, etc.]
double percentage = 0; // holds percentage of full scale data
char  printBuffer[200], cBuff[20], percBuff[20], pBuff[20], tBuff[20];
uint8_t cmd[3] = {0xAA, 0x00, 0x00}; // command to be sent
int i = 0;

Wire.beginTransmission(Address);
int stat = Wire.write (cmd, 3); // write command to the sensor
stat |= Wire.endTransmission();
delay(10); //
Wire.requestFrom(Address, 7); // read back Sensor data 7 bytes
 
 for (i = 0; i < 7; i++) {
 data [i] = Wire.read();
 }
 press_counts = data[3] + data[2] * 256 + data[1] * 65536; // calculate digital pressure counts
 temp_counts = data[6] + data[5] * 256 + data[4] * 65536; // calculate digital temperature counts
 *temperature = (temp_counts * 200 / 16777215) - 50; // calculate temperature in deg c
 percentage = (press_counts / 16777215) * 100; // calculate pressure as percentage of full scale
 //calculation of pressure value according to equation 2 of datasheet
 *pressure = (((press_counts - outputmin) * (pmax - pmin)) / (outputmax - outputmin) + pmin)-0.21;
}


void loop()
{
TCA.openChannel(TCA_CHANNEL_0);

ReadAbp2(id,&abppress1,&abptemp1);

Serial.print("Abp2 : ");
Serial.print(abppress1);
Serial.print(";");
Serial.print(abptemp1);
Serial.println("");

TCA.closeChannel(TCA_CHANNEL_0);

TCA.openChannel(TCA_CHANNEL_1);

ReadSht(SHT85_ADDRESS,&hum1,&temp1);
Serial.print("SHT2 : ");
Serial.print(hum1);
Serial.print(";");
Serial.print(temp1);
Serial.println("");
TCA.closeChannel(TCA_CHANNEL_1);
}

What does the simple usage sketch from the TCA9548A examples folder tell you? It opens all the channels and does a bus scan. You should get back the address of all the devices. Do you?

What if you enable all channels at the same time? If you don't get data then something is wrong with your hardware. Please provide a circuit diagram.

no, the ABP2 don't answer when it is connected on multiplexer. But if i use I2C scanner example from wire library, and connect the sensor directly on the I2C line, it was detected ...

Also if you enable all channels?

That is exactly what the SimpleUsage.ino sketch from the TCA9548A examples folder does.

Yes, but I just found the problem...

With all my apologies it's a simple problem of pull up resistor ..
i remove it before because SHT sensor work without it even on multiplexer channels BUT ABP2 sensor work without resistor on the arduino i2C line, but NOT on TCA channel !

Have a nice day, and thank you very much for your help :slight_smile: ! (blh64, you guided me in the right direction to find the solution ! thanks)

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