As the code uses unsigned int for the temperature readings which are coded as 2's complement signed values, you will get wrong readings if the device is exposed to cold weather (i.e. below 0°C).
I suggest to use some code like this:
int16_t DS3231_Simple::getTemperature()
{
return (int16_t)(DS3231_Simple::getTemperatureFloat() + 0.5);
}
float DS3231_Simple::getTemperatureFloat()
{
int16_t temp;
rtc_i2c_seek(0x11);
Wire.requestFrom(RTC_ADDRESS,(uint8_t) 2);
temp = Wire.read() << 8;
temp |= Wire.read();
return(temp/256.);
}
As the code uses
unsigned intfor the temperature readings which are coded as 2's complement signed values, you will get wrong readings if the device is exposed to cold weather (i.e. below 0°C).I suggest to use some code like this: