PiicoDev Precision Temperature Sensor TMP117 - Raspberry Pi Guide

Michael just shared a new tutorial: “PiicoDev Precision Temperature Sensor TMP117 - Raspberry Pi Guide”




Tutorial Video Coming Soon!

This guide will help you read temperature data from your PiicoDev® Precision Temperature Sensor and a Raspberry Pi single-board computer

1 Like

Temperature to 7 decimal places. Kidding right???
Device accuracy quoted 0.1ºC. Deteriorating as range increased. Still pretty good.
Cheers Bob

2 Likes

Haha! I knew it was only a matter of time before somebody picked up on that :wink: It’s purely a numerical quirk.
When writing the tutorial I didn’t want to burden beginners with the (intimidating) syntax of formatted print statements.
print(temperature) is a lot friendlier looking than print("{:.1f}".format(temperature))

and while Raspberry Pi (python3) does support F-strings, the Raspberry Pi Pico / micro:bit do not :confused:

1 Like

Hi Michael
I suppose the number can be manipulated before the “print” command to make it more realistic. But maybe not… I am not familiar with RPi or Python.
Cheers Bob

1 Like

The resolution and repeatability on that sensor are good to 2 decimal places though:

Resolution and repeatability are ±0.0078125°C!

It might not be true temperature, but if you’re just looking for changes it’s still very good. But yes, not 7 sig figs good though…

2 Likes

I would like to attach the TMP117 directly to a Raspberry Pi 4 Model B rather than use the adapter and that part is easy. But I would also prefer to use standard python3 but the problem is there do not seem to be any supporting libraries. Does anyone know if they are available?
Thanks

2 Likes

Hi @Fractal - welcome to the forums :smiley:
What do you mean by standard python3? The PiicoDev TMP117 module is just a collection of python3 functions to initialise and read from the sensor. The module should would with any TMP117 regardless of how it is physically connected to the Pi

If you prefer to roll your own approach, the TMP117 is about as simple as an I2C device can get - from memory you only have to execute a read across a 16-bit register to get temperature data.
(TMP117 datasheet)

You can reverse engineer our approach on pypi to get started if you like. Our package is made up of PiicoDev_TMP117.py which is the device driver, and PiicoDev_Unified.py which handles I2C compatibility between different MicroPython development boards (RPi Pico, RPi SBC, BBC micro:bit)

4 Likes

Have been using python3 and must confess not familiar with micropython. I assumed the micropython libraries would be written in C/C++ for speed and to suit the different boards. But just had a look at the package and yes they are actually python modules which makes it all so easy. I can see that if you were only using the TMP117 with a Raspberry Pi then the code could be considerably simplified. Also obvious was that the package was written by a highly talented software engineer :wink:

5 Likes

Have been using the Pimoroni BME280 for weather station and IOT applications. Some strange data prompted me to place two BME280 together and take readings. Shocked to find one read say 21.47 degC while the other read 23.02 degC and that is a considerable difference. The same thing with humidity and pressure. Rather than it being the silicon I suspect a gremlin crept into a library update. Many of the available temperature sensors are not all that accurate and that is why the TMP117 with 7 decimal places of accuracy :grinning: looks very attractive especially for calibration. I noticed that Core Electronics now have a BME280 and I will change to that in the future as well as trying the TMP117.

3 Likes

I think you can take the “*7 decimal places of accuracy” with a grain of salt. Refer earlier replies this thread.
There is an interesting video on an earlier thread which suggests the scientific boffins are still trying to work out a way to accurately measure 0ºC for standards use. Maybe someone could suggest one of these sensors if they are actually that good.
Cheers Bob
PS For a weather station where there could be several variables at play your 1.5ºC variation is not all that bad.

1 Like

@Fractal Yes, that’s just a little quirk of the code as the value printed is a float and there’s no subscripting used to make the string shorter as Michael is trying to cut down on the code.

This is a very hacky way to implement it. Although this script on your Pico will always print one decimal place (hacky as there is no rounding, this just cuts off the substring and it would be much neater to move this into another function with pre and post requirements specified, but it works on a Pico :sweat_smile:).

# PiicoDev TMP117 minimal example code
# This program reads the temperature from the PiicoDev TMP117 precision temperature sensor
# and displays the result in Degrees Celsius, Farenheit and Kelvin

from PiicoDev_TMP117 import PiicoDev_TMP117
from time import sleep

tempSensor = PiicoDev_TMP117()

while True:
    # Read and print the temperature in various units
    tempC = tempSensor.readTempC() # Celsius
    tempF = tempSensor.readTempF() # Farenheit
    tempK = tempSensor.readTempK() # Kelvin
    
    # Convert temperature into a string and print the data
    print(str(tempC)[:str(tempC).find('.')+2] + "°C")
    
    sleep(1) # delay

2 Likes

@Bryce similar to C/C++, python supports formatted print statements which allow eg.

  • printing to a prescribed precision
  • padding to create a known width

To round 2 decimal places:

>>> pi = 3.14159265359
>>> print(pi)
3.14159265359
>>> print("Pi is roughly {:.2f}".format(pi))
Pi is roughly 3.14

So a more a more ‘pythonic’ way to print temperature to two decimal places might be print("{:.2f}°C".format(tempC)).
I’ll admit converting to a string first is a bit of a red herring - we chose that for the example again to move away from this rather intimidating looking syntax.

More recent versions of python also support something called an “F-string” which is a super friendly and intuitive way to format a print statement - sadly F-strings aren’t implemented in micropython.

Definitely - at a minimum you would only need one call to i2c.read_word_data(TMP117_ADDR, REG_TEMP)
where TMP117_ADDR is the I2C address of the device, and REG_TEMP is the temperature register. Then multiply by the scaling factor in the datasheet.

3 Likes

Whoops. My comment about “7 decimal places of accuracy” was meant to be tongue in cheek and I started a dialogue on formatting. Sorry. I simply use temp_rounded = round(temp, 1) which rounds to one decimal place.

4 Likes

Will try the TMP117 - the ±0.1 deg accuracy appeals. The BME280 is ±0.5 deg but it does do pressure and humidity as well. Still trying to find why different revisions of the Pimoroni package give differing results but it may be related to compensate variables. The BME280 api is written in C and is complex so debugging is not easy. Off topic so will not mention it anymore.

2 Likes

I tried the TMP117 on a headless Rasperry Pi Zero W and had it going in minutes. Very impressed!
sudo raspi-config #Enable I2C
pip3 install piicodev #Install PiicoDev
pip3 list #Check library installed

The default address if 48 and from the circuit diagram I can see ADD0 is grounded via JP5.
If I wanted to change the address to say 49 should I cut through 1-2 on JP5 and solder bridge 1-2 on JP4 to pull ADD0 high?

In the python library I can see in PiicoDev_TMP117.py that the default address is 48.
To change the address to 49 in main.py should I set:
tempSensor.addr = 0x49

Would appreciate the help - do not want to wreck the board.

5 Likes

Hey Fractal! You’re right on the money - to change the address of the physical device:

Then, when you initialise the sensor, initialise it with the new address:

tempSensor = PiicoDev_TMP117(addr=0x49)

if no addr argument is given, the default 0x48 is used.

You could technically set the property manually tempSensor.addr=0x49 but this isn’t intended, and won’t work for most other devices.

3 Likes

Hi Michael. Thanks for your prompt reply. You saved me heaps of time.

4 Likes

Guys,
from what I understand looking at the above posts, and the picture on PiicoDev Precision Temperature Sensor TMP117 | Core Electronics Australia, the TMP117 has inbuilt facility for four addresses (4A,4B, 48, 49) by cutting tracks and/or soldering

Has anyone plugged four identical units into a raspberry pi to see how well the temperature readings track? Anyone? I’d be fascinated to see what kind of readings you get. Particularly if compared to a known, calibrated, precision temperature sensor.

Anyone got nothing better to do at the moment?

Cheers,
Allan H

3 Likes

I haven’t, but there’s a pretty good discussion about metrology and temperature references going on in the thread about this sensor:

Looks like @James84823 might be planning on doing just that…

3 Likes

Ta,
alh

3 Likes