How to interface the TMP116 & TMP117 temperature sensors with Arduino

Hello. Today, I will show you how to interface the TMP116 and TMP117 temperature sensors to an Arduino UNO using I squared C communication protocol. By the end of the video, you will have a better understanding of the basic functionalities of the TMP devices. You will learn how to output a measured temperature to LCD display and how to use the ALERT pin to trigger an interrupt. If you still have questions or want to learn more, check out the resources linked in the video description.
We'll start by going over the basic functionalities and differences of the TMP116 and TMP117. Then, we'll talk about how to communicate with the devices using I squared C to read and write to registers on the device. Following that, we'll go over how to use the ALERT pin to trigger an interrupt, and we'll also discuss some of the device registers and addresses. Then, I'll show you a working demonstration of both the TMP116 and TMP117 to continuously display temperature on the LCD. I'll also showcase the device's ALERT pin functionality and the TMP117's offset register. Finally, I'll go through the example code step by step to ensure you can follow along.
The TMP116 and TMP117 are local digital temperature sensors that are perfect for wearables, such as smartwatches, medical devices, and thermal protection and management applications, where high precision temperature readings are desired. The TMP116 provides an accuracy of plus or minus 0.25 degrees C from negative 40 to 105 degrees C. The TMP117, however, offers better accuracy over a wider temperature range, providing an accuracy of plus or minus 0.2 degrees C from negative 55 to 150 degrees C, which is comparable to certain platinum RTVs. The TMP117 is also an excellent device for medical applications requiring skin temperature measurements, offering an accuracy of plus or minus 0.1 degree C from 25 to 50 degrees C, which exceeds the ASTM E1112 requirements for electronic patient thermometer. Both devices provide a 16-bit temperature result, with a resolution of 7.8125 millidegrees C. More information on the electrical characteristics of each device can be found in the data sheets in the video description.
The devices use I squared C to communicate to the master device. I squared C is a two-wire communication protocol, which consists of two signals-- the SDA, serial data line, and SCL, serial clock line. These lines must be connected to the corresponding input pins on the Arduino. These pins will vary from part to part, but for the Arduino demo today, those are pins A4 and A5, respectively.
Since our devices can be very small and difficult to solder, TI offers evaluation modules, or EVMs, which can be a simple way to get started with our devices. TI has also developed GUIs that are free to download for simple and fast setup. The images on the slide show EVMs for the TMP116 and TMP117. The sensor is located at the end of the EVM and can be broken off to allow the sensor to be placed closer to the heat source. We will be using the same break out boards in the demo today.
The 3.3 volt pin from the Arduino Uno will be used to power the TMP116, but the IC can function optimally from 1.9 volts to 5.5 volts. The supply range of the TMP117 was improved to function optimally from 1.8 volts to 5.5 volts. Both devices have the ability to detect if the temperature has crossed a threshold. This is done by using the Therm and Alert modes built into the device.
Alert mode makes the device behave like a window limit detector by triggering a high or low alert flag to let the user know that the temperature has exceeded the limits. We will showcase the alert mode in the demonstration today.
Therm mode makes the device behave like a high limit threshold detector by triggering the high alert flag when the temperature has gone above the threshold. These temperature limits can be set by riding to the high and low limit registers.
The devices also have user programmable EEPROM that can be used to store power on reset values. The EEPROM has for 16-bit locations for general purpose use. More information on programming EEPROM for each device can be found in the datasheets included in the video description.
Another feature which differentiates the TMP117 is the addition of the temperature offset register. This allows the user to preprogram an offset, which will be added to the temperature result after linearization. This eliminates the need to write additional lines of code to incorporate this offset if desired.
The address for the TMP116 and TMP117 are hex 48. This is because the ADD0 pin is connected to ground by default. If there are multiple devices with the same address connected on the same I squared C line, then we need to change the address of the other devices so we can differentiate which device we want to communicate with. This can be done by changing where we connect the ADD0 pin.
The table on the slide shows the different addresses the TMP116 can have when the ADD0 pin is connected to ground, the voltage source, SDA, or SCL. An important thing to notice is that the wiring for the breakout boards are different even though their are pin configurations on the IC are the same. When working with these devices, it is important to ensure proper connections are made.
The TP116 and TMP117 use I squared C to communicate with the master device, which in our case is the Arduino Uno. To write to a register, there are four basic steps. First we must tell the master which device to control on the I squared C line by using a Wire.beginTransmission function with the device address as the argument. Next, the point to the register we want to write to by using the Wire.write command. For example, the configuration register is at address hex 01. To write to that register, we would write 0x01 into the argument of the Wire.write command.
Then, we send two bytes of data using the Wire.write command to the configuration register, which has 16 bits. The Wire.write command can only send one byte at a time, so we need to call this command twice in order to write all 16 bits. Finally, we use the Wire.endTransmission command to stop the transmission of data.
Reading from a register is similar to writing to a register, and I've broken it down into five basic steps. First, we point to the device on the I squared C line we want to communicate with by using the Wire.beginTransmission function with the device address as the argument. Next, we point to the register we want to read from by using the Wire.write command. For example, if we wanted to read from the temperature register, we would write 0x00 into the argument of the wire.Write command. Then, we stop data transfer by using the Wire.endTransmission function. This makes the I squared C line available to read. After that, we use the Wire.requestFrom function to request bytes from the slave device. The arguments for this function are the address of the device and the number of bytes to request. Here, I am requesting two bytes from the same sensor device previously selected. Finally, we read in the data that was transmitted by the Wire.read function. The data is read one byte at a time, so we have to call this function twice since the temperature register contains 16 bits of data.
These devices have the ability to detect if the temperature has gone outside of a certain temperature range. It does so by comparing the converted temperature result to the value stored in the high and low limit registers. It is also important to note the polarity of the ALERT pin. By default, the ALERT pin is active low.
In alert mode, if the temperature exceeds the limit, the high alert or low alert status flags are set, and this causes the ALERT pin to get asserted. The ALERT pin can be de-asserted by performing an I squared C read of the configuration register. To use the ALERT pin as an interupt in the Arduino Uno IDE, there are three important steps. Within the set up block, set the pin on the Arduino as an input by using the pinMode function. For the Arduino Uno, only digital pins 2 and 3 can be used for interrupts. Also, remembering the fact that the ALERT pin is by default active low, I use the know built in pull up resistor to invert the behavior of pin 2 to match the behavior of the ALERT pin.
Then, we enable the interrupt by using the attachInterrupt command. The first parameter selects the digital pin number to trigger the interrupt. The second declares the name of the ISR, or interrupt service routine, and the third defines how the interrupt triggers. Here, I set digital pin 2 trigger my alert ISR whenever the pin changes value. Finally, we have to create the ISR which we called in attachInterrupt command. Any code we want to occur when the interrupt triggers should be put here.
Here, we have listed the registers and addresses for the TMP116 and TMP117. Everything is the same except at address hex seven. And the TMP117, the EEPROM3 register was replaced with a temperature offset register. This register allows the user to preprogram an offset, which will be added to the temperature result after linearization. This eliminates the need to write additional lines of code to incorporate this offset if desired.
Now, I'll show you a working demonstration of the TMP116 and TMP117. Here, we have the TMP116 configured to display its temperature readings continuously on the LCD display. From left to right, we have the TMP116 breakout, an LED, an LCD display, and a 10K potentiometer to control the backlight of the LCD. The temperature limits have been set at 24 degrees Celsius for the low limit and 27 degrees Celsius for the high limit. If the temperature goes outside of that range, the device will assert the ALERT pin, trigger the interrupt, and cause the led to blink and the LCD display, "Alert."
It was abnormally cold in the office so you can see by placing my finger over the TMP116, I was actually able to decrease the temperature reading from 24.27 C to just under 24 C, causing the low limit alert to trigger.
Here, we have the TMP117 configured to display its temperature. Now, after warming my hands, you can see the temperature increase from almost 25 C to just over 27 C, triggering the high alert.
I'll now reprogram the TMP117 to include an offset of 25 C. Now, the temperature reading is 25 C greater than it was before, but it still changes at the same rate when I place my finger over it. It's also important to notice that the high and low limits remain the same and were not affected by the offset, which is why the alert is still being triggered. The schematic showing the connections of these setups is available in the video description.
We will now step through the example code, which corresponds to the demonstration we just saw. After opening the Arduino IDE, we include the Wire.h and LiquidCrystal.h libraries to utilize I squared C communication and the LCD display. These libraries should be available in most Arduino IDEs. I've defined the default address for the TMP device and various registers for reference. I've also included the offset register, which is specific only to the TMP117.
Then, we declare the pin assignments for the LCD that match the schematic. The setup block contains the code the Arduino will run once. Within this block we initialize the Arduino as the master in I squared C communication and begin serial communication. Then, we initialize the 16 by 2 LCD display to print the temp C label. Then, we use the I squared C write function to write to registers. This function takes in four arguments-- the device's address, the register we want to write to, and then the high and low bytes of data written to that register. I use this function to write the high and low limits to be 27 degrees C and 24 degrees C.
Also within the setup block, we set pin 13 as an output to drive the LCD and pin 2 as an input to drive the interrupt. Then, we enable the interrupt to trigger the ISR whenever the pin changes value. Finally, we take in the startup value the ALERT pin reads.
The loop block contains the code the Arduino runs continuously. Within this block, we call the ReadTempSensor function to retrieve the temperature reading. The next two lines set the cursor on the LCD to print the temperature after the temp C label. The if else block is dependent on a variable alarm, which is changed within the ISR. The interrupt triggers when the ALERT pin changes value. The variable alarm takes the value from digital pin 2. This value will either be high or low, and it tells us the state of the ALERT pin. If the ALERT pin is active low, the LCD will blink and display alert on the LCD. We perform an I squared C read of the configuration register to de-assert the ALERT pin. When the ALERT pin is active high, the LED turns off, indicating that the temperature is within the normal range.
The ReadTempSensor performs steps to read from the temperature register via the I squared C line. We discussed how to read from a register using I squared C earlier in the video, and you can go back to that slide for reference, if needed. After the data is stored into variable's DATA0 and DATA1, the data in DATA0 is shifted left 8 bits and then concatenated with DATA1 to create a 16-bit binary number that is stored into the DATAC variable.
Because this device has 7.8125 milliC resolution, we return the product of our 16-bit number multiplied by this resolution. This gives us our temperature in degrees Celsius.
In the video description, I've included links to download separate example codes for the TMP116 and TMP117.
This concludes the demonstration on how to interface the TMP116 and TMP117 temperature sensors with an Arduino. Both example codes and the schematic for the demonstrations are available in the video description. To learn more about these devices, please refer to the following resources. Thank you for watching and stay tuned for future videos on how to utilize other TI sensor products with Arduino.

Description

August 3, 2018

The TMP116 is a low-power, high-precision temperature sensor with integrated EEPROM memory. The device provides a 16-bit temperature result with a resolution of 0.0078°C and an accuracy of up to ±0.2°C with no calibration. The TMP116 consumes minimal current, typically 3.5µA, which minimizes self-heating and improves measurement accuracy. The TMP117 is similar to the TMP116 but it is designed to exceed ASTM E1112 requirements for electronic patient thermometers and has an accuracy of up to ±0.1°C across the temperature range of 25°C to 50°C. Both devices are I2C- and SMBus™ interface compatible and have programmable alert functionality.

In this tutorial you will learn how to output temperature in Celsius to a LCD display, as well as how to use the alert functionality on the devices. First, we will cover the basic functionalities and differences of the TMP116/TMP117, as well as how to communicate with the devices using I2C to read and write to registers on the device. Following that, we will go over how to use the ALERT pin to trigger an interrupt. Finally, we will show a working demonstration of the TMP116/TMP117 and we will go step-by-step through the example code so you can reproduce the same results on your own.