Adafruit TMP117: a 0.1 °C digital thermometer
Yes. You can use the Adafruit TMP117 library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Temperature sensor, TMP117). The example below, "The temperature from a TMP117", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_TMP117.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit TMP117 does
The TMP117 from Texas Instruments is a digital temperature sensor rated to within 0.1 °C. It reports in steps of 7.8125 thousandths of a degree over I2C, at 0x48 by default. Adafruit’s library returns each reading as a Unified Sensor event.
Part of that accuracy comes from averaging. After begin() the chip averages 8 conversions and delivers a new result about once a second. setAveragedSampleCount() changes the averaging, more for less noise and fewer for speed, and setReadDelay() adds idle time between results to save power. getEvent() waits for the data-ready flag, so every call returns a new result rather than repeating the last.
The chip can also watch a temperature on its own. setHighThreshold() and setLowThreshold() set limits, and getAlerts() reports which were crossed since it was last asked, while the ALERT pin signals the same to an interrupt. SparkFun makes a TMP117 library with different calls; this page covers Adafruit’s. In Mokxi the tmp117 part reports its slider exactly, to the 7.8125 m°C step, where a real part is within 0.1 °C.
| Library Manager name | Adafruit TMP117 |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_TMP117.h>#include <Adafruit_TMP119.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Temperature sensor, TMP117 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Adafruit_TMP117.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit TMP117" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit TMP117 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.5, so a sketch written here builds there too.
What to know in the simulator: The reading is the slider exactly, to 7.8125 m°C; the real part is within 0.1 °C.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- ESP32-S3-CAM
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
Adafruit_TMP117 tmp117
Creates the driver.
tmp117.begin()
Checks the device ID at 0x48 and resets the chip. Pass another address, such as begin(0x49), when ADD0 is wired differently.
tmp117.getEvent(&temp)
Waits for a new conversion and puts degrees Celsius in temp.temperature.
sensors_event_t temp;
tmp117.getEvent(&temp);
Serial.println(temp.temperature);tmp117.dataReady()
True when a new result is waiting, for a loop that should not block.
tmp117.setAveragedSampleCount(TMP117_AVERAGE_64X)
Averages 64 conversions per result. TMP117_AVERAGE_1X is fastest and noisiest.
tmp117.setReadDelay(TMP117_DELAY_4000_MS)
Adds idle time so a result comes every four seconds, which saves power on a battery logger.
tmp117.setMeasurementMode(TMP117_MODE_ONE_SHOT)
Takes one result and then rests until asked again. TMP117_MODE_CONTINUOUS is the default.
tmp117.setOffset(-0.25)
Adds the given offset in degrees to every reading (a negative value subtracts), for a correction you measured against a reference.
tmp117.setHighThreshold(30.0)
Sets the upper alert limit in degrees; setLowThreshold() sets the lower one.
tmp117.getAlerts(&alerts)
Fills a tmp117_alerts_t: alerts.high, alerts.low and alerts.data_ready, the flags seen since the last call.
Example: The temperature from a TMP117
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <Wire.h>
#include <Adafruit_TMP117.h>
#include <Adafruit_Sensor.h>
Adafruit_TMP117 tmp117;
void setup(void) {
Serial.begin(115200);
if (!tmp117.begin()) {
Serial.println("Failed to find TMP117 chip");
while (1) {
delay(10);
}
}
Serial.println("TMP117 Found!");
}
void loop() {
sensors_event_t temp;
tmp117.getEvent(&temp);
Serial.print("Temperature ");
Serial.print(temp.temperature);
Serial.println(" degrees C");
delay(1000);
}Wiring
- Arduino Uno R3 A4 to Temperature sensor, TMP117 SDA
- Arduino Uno R3 A5 to Temperature sensor, TMP117 SCL
- Arduino Uno R3 5V to Temperature sensor, TMP117 VIN
- Arduino Uno R3 GND to Temperature sensor, TMP117 GND
Common errors and how to fix them
Failed to find TMP117 chip
begin() did not read the TMP117 device ID at the address given. Check the bus wires and power, and pass the address that ADD0 selects if it is not 0x48.
Each pass of loop() takes a second or more
getEvent() waits for a fresh conversion, which with the default averaging comes about once a second, and later with a read delay. Check dataReady() and do other work in between.
The reading sits slightly above a reference thermometer
The sensor measures its own board, which nearby regulators and chips can warm. Mount it away from them, then measure the difference once and correct it with setOffset().
Questions and answers
Why does the TMP117 example include Adafruit_Sensor.h?
getEvent() fills a sensors_event_t, which that header defines. The driver includes it anyway, so the line is there to match Adafruit’s own example.
How do alerts work without the ALERT pin?
getAlerts() reads the same flags over I2C, so a sketch can poll it in loop(). The pin only matters when you want an interrupt instead.
Projects that use Adafruit TMP117
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Keep going
Learn
Try Adafruit TMP117 without installing anything
Open the example, change the sketch, and keep your version in a free account.