However I noticed that the decimal part of the temperature values in the controller was always zeroes but the serial monitor showed the correct decimal values. A temperature that shows for example 23.81 degC in the serial monitor showed up as 23.00 degC in the controller. I investigated this and found this line to be the problematic one.
Code: Select all
temp=int(temerature*100);
Somehow when I compile this (using Arduino 1.6.5, Z-Uno 2.06 on Linux) it gets translated into:
Code: Select all
temp = (int)temerature * 100;
A workaround for this problem is to add more parenthesis, like this:
Code: Select all
temp=int((temerature*100));
But since the ZUNO_DS18B20 library has a function to get the temperature as an int and already multiplied by 100, called getTempC100(), it is better to write the code in the other way around like this:
Code: Select all
// obtaining readings from the sensor ds18b20
temp = ds1820.getTempC100(addr1);
// make descaled float value for serial print
float temperature = (float)temp / 100.0;
Do someone have an explanation of why the function-style casting of int(temperature*100) doesn't work as expected?