//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);
}