Skip to content

Calibrate()

Arnd edited this page Dec 12, 2020 · 3 revisions

Calibrate([iterations][,CalibrationTemperature)

While each thermometer at maximum 12 bit resolution can detect changes of 0.0625°C, it is only accurate to "±0.5°C Accuracy from -10°C to +85°C" according to the datasheets. Several DS-Family devices that are at the same temperature will have a potential temperature spread of 1°C although they should read the same.

This calibration function assumes that all attached DS-Family devices are at the same temperature and averages the values over iterations temperature conversions for all devices, defaulting to 30. This overall average is uses as the "correct" temperature and all of the devices have a ±offset applied to them so that they read the same.

This calibration offset is stored in persistent user bytes 1 & 2. These bytes can be used for setting minimum and maximum temperature alarms and in order to ensure that no inadvertent offsets are used the values of the two bytes are set so that when xORd together the result is 0xFF; this condition is not likely to happen when the two user bytes are used for alarms.

Since each conversion can take up to 750ms, the default 30 iteration loop will take over 20 seconds to complete. The total time taken is independent of the number of thermometers on the 1-Wire microLAN and depends solely on the number of iterations. The devices are all set to maximum precision as part of the calibration process.

By default the calibration values, when set, are automatically applied to readings via ReadDeviceTemp() although an optional parameter in that function call allows the raw value to be read.

The second parameter, CalibrationTemperature allows setting all the thermometers to read the same calibrated temperature. This value is passed in as hectoCelsius, so a value of 18.56°C needs to be multiplied and passed in as an integer "1856".

The library includes an example calibration program which also shows the standard deviation values before and after calibration.


Example:

const uint8_t ONE_WIRE_PIN = 8;             // 1-Wire microLAN pin
DSFamily_Class ds(ONE_WIRE_PIN);            // Instantiate
uint8_t thermometers = ds.ScanForDevices(); // find all devices
Serial.print("Found ");
Serial.println(thermometers);
ds.Calibrate(30);                           // Calibrate over 30 iterations
for (uint8_t i=0;i<thermometers;i++) {
 Serial.print("Thermometer ");
 Serial.print(i);
 Serial.print(" has a calibration offset of ");
 Serial.print(ds.GetDeviceCalibration(i));
 Serial.print(" units, or ");
 Serial.print(ds.GetDeviceCalibration(i)*0.0625,3);
 Serial.println("C.");
} // of for-next each thermometer