Skip to content

ReadDeviceTemp()

Arnd edited this page Dec 3, 2016 · 1 revision

ReadDeviceTemp(DeviceIndex[,RawMode);

This ReadDeviceTemp() function returns a signed 16 bit number representing the temperature conversion result of the device specified in DeviceIndex. Each unit returned equates to 0.0625°C, for example a temperature value of "325" equates to 20.3125°C. To avoid floating point arithmetic on the Atmel processors, multiply by 625 and then divide by 100, giving an integer "2031" which would be the temperature Celsius times 100; or hectodegrees.

If the RawMode parameter is not specified or it is set to "false", then the calibration offset for the device, if present, is applied to the measurement and a calibrated reading is returned. If the parameter is set to "true", then the raw reading from the device is returned.

Note that the call will automatically wait for any active conversions to finish before retrieving the values.


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
ds.DeviceStartConvert();                    // Start conversion on all devices
for (uint8_t i=0;i<thermometers;i++) {
   Serial.print("Device "); 
   Serial.print(i);
   Serial.print(" reads "):
   int16_t temp = ds.ReadDeviceTemp(i)
   Serial.print(temp);
   Serial.print(" units, or ");
   Serial.print(temp*0.0625,3);             // use floating point degrees
   Serial.println("C.");
} // of for-next loop