TMP421, JeeNode and below freezing temps
Posted: Fri Dec 03, 2010 10:43 pm
Hello,
My TMP421 sensor running on the JeeNode worked great until the temps dropped below freezing. All of a sudden, the math to determine the temperature doesn't work! Here's the part of the sketch that pulls the bytes representing the temperature out of the TMP421:
DeviceI2C temperature (1, 0x2A); // I2C address of 0X2A
temperature.send(); // go into send mode
temperature.write(0x00); // high byte is on register 0
temperature.receive(); // grab it
temp_hi = temperature.read(1); // store it
temperature.stop(); // done
temperature.send(); // go into send mode
temperature.write(0x10); // low byte is on register 0x10
temperature.receive(); // grab it
temp_lo = temperature.read(1); // store it
temperature.stop(); // done
tempC = (float)temp_lo / 256; // make low byte into remainder
tempC = tempC + temp_hi; // add high byte to make total temp
(above was adapted from http://www.ka1kjz.com/?p=797)
So this is all fine and dandy until the temp drops below 0C. Once it does, I get values like 251 for temp_hi and 192 for temp_lo. Do the math and that's 251.75. With snow on the ground, I don't think that's likely.
Any idea how this should be adapted to handle below-freezing temps?
My TMP421 sensor running on the JeeNode worked great until the temps dropped below freezing. All of a sudden, the math to determine the temperature doesn't work! Here's the part of the sketch that pulls the bytes representing the temperature out of the TMP421:
DeviceI2C temperature (1, 0x2A); // I2C address of 0X2A
temperature.send(); // go into send mode
temperature.write(0x00); // high byte is on register 0
temperature.receive(); // grab it
temp_hi = temperature.read(1); // store it
temperature.stop(); // done
temperature.send(); // go into send mode
temperature.write(0x10); // low byte is on register 0x10
temperature.receive(); // grab it
temp_lo = temperature.read(1); // store it
temperature.stop(); // done
tempC = (float)temp_lo / 256; // make low byte into remainder
tempC = tempC + temp_hi; // add high byte to make total temp
(above was adapted from http://www.ka1kjz.com/?p=797)
So this is all fine and dandy until the temp drops below 0C. Once it does, I get values like 251 for temp_hi and 192 for temp_lo. Do the math and that's 251.75. With snow on the ground, I don't think that's likely.
Any idea how this should be adapted to handle below-freezing temps?