problem with ZUNO_DS18B20 with sub zero temperatures
Posted: 14 Dec 2022 16:41
Hello,
I used example code provided for Z-UNO. Everything works fine when measuring positive temperatures.
But with freezing temperatures I noticed results are not correct.
Either library ZUNO_DS18B20 has not correct logic to convert temperatures or it is lacking it and I am supposed to add some transformation to get correct negative temperatures? Please advise.
Normally values returned by sensor I am multiplying by 100 as per the rules on your website. But for negative temperatures it doesn't seem to work.
Unless I mixed up sizes/precision for calculation. But I have size 2 and precision 2 for SENSOR MULTILEVEL. I think I am not even getting there as the value returned by sensor doesn't fit. So, I suspect Library has a problem to convert it correctly.
https://z-uno.z-wave.me/Reference/ZUNO_ ... ULTILEVEL/
Values returned by getter are signed. Values are interpreted according to the following transformation:
signed value = value / 10precision, for value < MAX_NUM/2
signed value = (value - MAX_NUM) / 10precision, for value ≥ MAX_NUM/2
Where MAX_NUM = 28*size and precision defined number of decimal digits after dot.
For example if size 1 and precision 0, value 25 represents 25,
for size 1 and precision 0, value 164 represents -92 = 164 - 256,
for size 1 and precision 1, value 25 represents 2.5 = 25 / 10,
for size 1 and precision 1, value 164 represents -9.2 = (164 - 256) / 10,
for size 2 and precision 1, value 366 represents 36.6,
for size 2 and precision 1, value 65535 represents -0.1 = (65535 - 65536) / 10,
for size 2 and precision 2, value 65535 represents -0.01 = (65535 - 65536) / 100.
my code below and I tried adjusting resolutions etc but nothing works
// demo sketch for connecting OneWire temperature sensor DS18B20 to Z-Uno
// add library ds18b20
#include <ZUNO_DS18B20.h>
#include <ZUNO_OneWire.h>
// pin connection ds18b20
#define PIN_DS18B20 11
#define N_SENSOR 1
#define MAX_NUM 65536
#define MAX_NUM2 32768
OneWire ow(PIN_DS18B20);
// onewire connection temperature sensors
DS18B20Sensor ds1820(&ow);
byte addr1[8];
word temp; // Here we store temperatures
float value;
word paramValue;
word resolution
ZUNO_SETUP_CFGPARAMETER_HANDLER(config_parameter_changed);
// ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
// set up channel
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
getterTemp)
);
void setup() {
Serial.begin(9600);
Serial.println("start");
// paramValue = zunoLoadCFGParam(11);
}
//void config_parameter_changed(byte param, word value) {
// if (param == 11) { // The first user-defined parameter
// paramValue = 60;
// }
//}
void loop() {
// word value = zunoLoadCFGParam(byte param);
// zunoSaveCFGParam(11, paramValue);
delay(30000);
ds1820.scanAloneSensor(addr1);
// obtaining readings from the sensor ds18b20
float temerature = ds1820.getTemperature(addr1);
// float temerature = ds1820.getTempC100(addr1);
resolution = ds1820.getResolution();
ds1820.setResolution(2,NULL);
Serial.print("Your resolution is: ");
Serial.println(resolution);
// make scaled word value for report
// temp=int(temerature*10);
Serial.print("Your sensor address is: ");
for(byte i = 0; i < 1; i++) {
// print OneWire code
Serial.print(addr1, HEX);
Serial.print(" ");
// value = (float)temerature/16;
value = temerature;
if (value < MAX_NUM2) {
temp = float(value*100);
} else {
temp = float((value - MAX_NUM)/100);
}
// temp = float(temerature*100);
// temp = -500;
Serial.print("Temp: ");
Serial.println(temp);
// zunoSendReport(1);
}
Serial.println();
Serial.print("Temperature: ");
Serial.println(temerature);
Serial.print("Temp: ");
Serial.println(temp);
Serial.print("value: ");
Serial.println(value);
// send data to channel
zunoSendReport(1);
// send every 30 second
// delay(100);
// zunoSetBeamCountWU(30);
// zunoSendDeviceToSleep();
}
word getterTemp() {
return temp;
}
I used example code provided for Z-UNO. Everything works fine when measuring positive temperatures.
But with freezing temperatures I noticed results are not correct.
Either library ZUNO_DS18B20 has not correct logic to convert temperatures or it is lacking it and I am supposed to add some transformation to get correct negative temperatures? Please advise.
Normally values returned by sensor I am multiplying by 100 as per the rules on your website. But for negative temperatures it doesn't seem to work.
Unless I mixed up sizes/precision for calculation. But I have size 2 and precision 2 for SENSOR MULTILEVEL. I think I am not even getting there as the value returned by sensor doesn't fit. So, I suspect Library has a problem to convert it correctly.
https://z-uno.z-wave.me/Reference/ZUNO_ ... ULTILEVEL/
Values returned by getter are signed. Values are interpreted according to the following transformation:
signed value = value / 10precision, for value < MAX_NUM/2
signed value = (value - MAX_NUM) / 10precision, for value ≥ MAX_NUM/2
Where MAX_NUM = 28*size and precision defined number of decimal digits after dot.
For example if size 1 and precision 0, value 25 represents 25,
for size 1 and precision 0, value 164 represents -92 = 164 - 256,
for size 1 and precision 1, value 25 represents 2.5 = 25 / 10,
for size 1 and precision 1, value 164 represents -9.2 = (164 - 256) / 10,
for size 2 and precision 1, value 366 represents 36.6,
for size 2 and precision 1, value 65535 represents -0.1 = (65535 - 65536) / 10,
for size 2 and precision 2, value 65535 represents -0.01 = (65535 - 65536) / 100.
my code below and I tried adjusting resolutions etc but nothing works
// demo sketch for connecting OneWire temperature sensor DS18B20 to Z-Uno
// add library ds18b20
#include <ZUNO_DS18B20.h>
#include <ZUNO_OneWire.h>
// pin connection ds18b20
#define PIN_DS18B20 11
#define N_SENSOR 1
#define MAX_NUM 65536
#define MAX_NUM2 32768
OneWire ow(PIN_DS18B20);
// onewire connection temperature sensors
DS18B20Sensor ds1820(&ow);
byte addr1[8];
word temp; // Here we store temperatures
float value;
word paramValue;
word resolution
ZUNO_SETUP_CFGPARAMETER_HANDLER(config_parameter_changed);
// ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
// set up channel
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
getterTemp)
);
void setup() {
Serial.begin(9600);
Serial.println("start");
// paramValue = zunoLoadCFGParam(11);
}
//void config_parameter_changed(byte param, word value) {
// if (param == 11) { // The first user-defined parameter
// paramValue = 60;
// }
//}
void loop() {
// word value = zunoLoadCFGParam(byte param);
// zunoSaveCFGParam(11, paramValue);
delay(30000);
ds1820.scanAloneSensor(addr1);
// obtaining readings from the sensor ds18b20
float temerature = ds1820.getTemperature(addr1);
// float temerature = ds1820.getTempC100(addr1);
resolution = ds1820.getResolution();
ds1820.setResolution(2,NULL);
Serial.print("Your resolution is: ");
Serial.println(resolution);
// make scaled word value for report
// temp=int(temerature*10);
Serial.print("Your sensor address is: ");
for(byte i = 0; i < 1; i++) {
// print OneWire code
Serial.print(addr1, HEX);
Serial.print(" ");
// value = (float)temerature/16;
value = temerature;
if (value < MAX_NUM2) {
temp = float(value*100);
} else {
temp = float((value - MAX_NUM)/100);
}
// temp = float(temerature*100);
// temp = -500;
Serial.print("Temp: ");
Serial.println(temp);
// zunoSendReport(1);
}
Serial.println();
Serial.print("Temperature: ");
Serial.println(temerature);
Serial.print("Temp: ");
Serial.println(temp);
Serial.print("value: ");
Serial.println(value);
// send data to channel
zunoSendReport(1);
// send every 30 second
// delay(100);
// zunoSetBeamCountWU(30);
// zunoSendDeviceToSleep();
}
word getterTemp() {
return temp;
}