This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMP117: Interpreting temperature read-out on Raspberry Pi

Part Number: TMP117

We are using the smbus2 library in Python to read data coming from a TMP117 sensor. Using the .read_i2c_block_data() method we have printed out the sensor data. We observe the following array when we specify the block length as 3: [12, some number between 170 - 220, 255], and any increase in block length yields more 255’s. While these numbers must have something to do with the temperature measured by the sensor, it is unclear how to decipher the actual temperature value from these. We have looked through the data sheet and can not find a clear explanation as to how one should interpret the data. We are wondering if someone could provide insight into how to convert this output into temperature in degrees celsius. Thanks in advance!

  • Hi Christopher,

    Thank you for posting to the Sensing forum.

    The temperature data in the result register is in two's complement format (see excerpt from datasheet below) and each LSB corresponds to 7.8125 m°C. You will only need to request two bytes from the TMP117 to retrieve the temperature result.

    You may refer to the code example below, which takes a temperature register result of 0x0C40 and converts it into m°C and °C. The resulting bytes are converted into a decimal value and multiplied by the device resolution (0.0078125 °C) in order to convert to °C.

    uint8_t byte1 = 0xC;
    uint8_t byte2 = 0x40;
    float f = ((int8_t) byte1 << 8 | byte2) * 0.0078125f;
    int mC = ((int8_t) byte1 << 8 | byte2) * 1000 >> 7;
    int C = ((int8_t) byte1 << 8 | byte2) >> 7;

    Best regards,
    Nicole

  • Hi Nicole,

    Thanks so much! It was not originally clear to me that I had to use only the first two bytes and combine them in this way (testing different values of the sensor output was bringing me closer to this), but looking back now with the information you gave me makes more sense. This resolved my issue.

    Regards,

    Chris