The library for SHT31 is not working properly

I am trying to use a SHT31 sensor with its library, but when I declare sht31.begin () if the sensor is not connected the command never exits and I cannot manage the error. below the code that I am testing.
do you have any ideas?

#include <Arduino.h>
#include <Wire.h>
#include “SHT31.h”

SHT31 sht31 = SHT31();

void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println(“begin…”);
//sht31.begin();
if (! sht31.begin()) {
Serial.println(“Couldn’t find SHT31”);
while (1) delay(1);
}
}

void loop() {
float temp = sht31.getTemperature();
float hum = sht31.getHumidity();
Serial.print(“Temp = “);
Serial.print(temp);
Serial.println(” C”); //The unit for Celsius because original arduino don’t support speical symbols
Serial.print(“Hum = “);
Serial.print(hum);
Serial.println(”%”);
Serial.println();
delay(1000);
}

Can you share the error you are getting?

Hi @salam, the problem is that I do not return any error when I run sht31.begin () the program remains blocked waiting for the sensor and if the sensor has a problem or is disconnected the program does not go further.

@salman I entered this step
if (! sht31.begin ()) {
Serial.println (“Couldn’t find SHT31”);
while (1) delay (1);
}
and on arduino uno and the adafruit library works. I also tried to use the adafruit library but I have the same result maybe it is the management from I2C which is different?

Hi @salman, I did further tests and the problem arises when I disconnect the positive pole of the sensor. If one of the two branches of the I2C is disconnected the library behaves correctly and detects the fault, if disconnected the positive pole the library remains in idle and does not exit the command.

ohh, now it’s working, did you managed to solve the error?

Hi @salman, no I just found out in which situation the error occurs or when the SDA and SCL negative are connected and the positive pole is not connected. In this situation the sht31.begin(0x44) command remains in Idle

If, on the other hand, I disconnect SDA or SCL or the I2C doesn’t communicate correctly, the library correctly exits with the error

Can you share the error log?

@salman, as I wrote to you the problem is precisely the lack of errors after the begin command the library remains in IDLE does not go further and blocks the execution of the whole program. Since it cannot catch the error, it cannot be handled and the whole program execution fails.

May I know why used this while statement? it’s an infinite one, so try to remove that or try to the programme I was attaching.

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

SHT31 sht31 = SHT31();

void setup() {
    Serial.begin(9600);
    while (!Serial);
    Serial.println("begin...");
    sht31.begin();
}

void loop() {
    float temp = sht31.getTemperature();
    float hum = sht31.getHumidity();
    Serial.print("Temp = ");
    Serial.print(temp);
    Serial.println(" C"); //The unit for  Celsius because original arduino don't support speical symbols
    Serial.print("Hum = ");
    Serial.print(hum);
    Serial.println("%");
    Serial.println();
    delay(1000);
}

Hi @ salman, I tested your code but the result is the same as you can see from the photo of the Serial Monitor the program stops if I disconnect the positive pole from the sensor