I'm building a library to retrieve data from an adafruit sensor (sht31d)
The temperature reading appears accurate, but the humidity doesn't change.
My debug:
temp: 23.36 humid: 0.39
The following method is called in main.c
(method from sht31.c):
bool readTempHum(void)
{
uint8_t readbuffer[6];
writeCommand(SHT31_MEAS_HIGHREP);
_delay_ms(500);
for (uint8_t i=0; i<6; i++)
{
readbuffer[i] = read8(SHT31_DEFAULT_ADDR);
}
uint16_t ST, SRH;
ST = readbuffer[0];
ST <<= 8;
ST |= readbuffer[1];
SRH = readbuffer[3];
SRH <<= 8;
SRH |= readbuffer[4];
double stemp = ST;
stemp *= 175;
stemp /= 0xffff;
stemp = -45 + stemp;
temp = stemp;
double shum = SRH;
shum *= 100;
shum /= 0xFFFF;
humidity = shum;
return true;
}
To view the full implementation please click here
Thanks