SHT31 negative temp issue

Hello,

I have an issue with a SHT31-D and wemos D1 mini pro. It's done for -40°C - +65°C.
I use the code below, but I have an issue when temperature is negative.
I got value : 42949672.0°C instead of negative value. For positive value, no problem !
Humidity is fine even temp is negative.
Do I miss something ? Is there any tips.

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

Adafruit_SHT31 sht31 = Adafruit_SHT31();

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

  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SHT31 test");
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
}


void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
  Serial.print("Temp *C = "); Serial.println(t);
  Serial.print("Hum. % = "); Serial.println(h);
  delay(1000);
}

thanks in advance

Have a look into the Adadfruit SHT31 library (Adafruit_SHT31.cpp).

 uint32_t stemp = ((uint32_t)readbuffer[0] << 8) | readbuffer[1];
  // simplified (65536 instead of 65535) integer version of:
  //temp = (stemp * 175.0f) / 65535.0f - 45.0f;
  stemp = ((4375 * stemp) >> 14) - 4500;
  temp = (float) stemp / 100.0f;

Try the version they have commented out and comment the last two lines. Maybe there is an issue with the conversion in the "simplified" version.

Hi Klaus,

thanks for your feedback, I have found solution.
After checking my amazon order and sensor specs, it appears that model SHT31-D cannot run under zero (Humidity)
The model SHT31-A can do it ...

So for my weather station, it's a little problem ::slight_smile:
I have replaced this sensor y DHT22 ... and that works.

Case can be closed