TMP006 Contact-less Infrared (IR) Thermopile Temperature Sensor Driver in Rust

TMP006 measuring a tea cup

I have been writing several platform-agnostic Rust drivers (15 published at the moment) as a way to push embedded development in Rust forward. Today I present you a Rust driver for the TMP006.

The TMP006 is a pretty cool device that can measure the temperature of an object without touching it. An infrared thermopile.

The devices

The TMP006 and TMP006B are the first in a series of temperature sensors that measure the temperature of an object without the need to make contact with the object. This sensor uses a thermopile to absorb the infrared energy emitted from the object being measured and uses the corresponding change in thermopile voltage to determine the object temperature.

Infrared sensor voltage range is specified from -40°C to +125°C to enable use in a wide range of applications. Low power consumption along with low operating voltage makes the device suitable for battery-powered applications. The low package height of the chip-scale format enables standard high- volume assembly methods, and can be useful where limited spacing to the object being measured is available.

The communication is done serially through an I²C, bidirectional bus.

Datasheet: TMP006/B
User guide: TMP006 user guide

You can buy this from Adafruit or AliExpress.

The driver

This driver allows you to:

  • Enable/disable the device. See: enable().
  • Read the object temperature. See: read_object_temperature().
  • Read the object voltage and ambient temperature raw data. See: read_sensor_data().
  • Calculate the object temperature from the sensor raw data. See: calculate_object_temperature().
  • Set the ADC conversion rate. See: set_conversion_rate().
  • Enable/disable the DRDY pin. See: enable_drdy_pin().
  • Read whether data is ready to be read. See: is_data_ready().
  • Perform a software reset. See: reset().
  • Read the manufacturer ID. See: read_manufacturer_id().
  • Read the device ID. See: read_device_id().

Using the driver

To use the device from Rust, you have to add the tmp006 crate to your project as well as a concrete implementation of the embedded-hal traits. For example if you are using the Raspberry Pi running Linux, you can use linux-embedded-hal.

1
2
3
4
5
# Cargo.toml
...
[dependencies]
tmp006 = "0.2"
linux-embedded-hal = "0.1"

This is an example program which will measure the temperature and print it (in Kelvins).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
extern crate linux_embedded_hal as hal;
extern crate tmp006;

use hal::I2cdev;
use tmp006::{Tmp006, SlaveAddr};

fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = Tmp006::new(dev, address);
let calibration_factor = 6e-14;
let temperature = sensor
.read_object_temperature(calibration_factor)
.unwrap();
println!("Temperature: {}K", temperature);
}

This example is also available in the crate sources here.

I created a separate repository for additional examples: tmp006-examples.
There you can find the code of the program running on the title image of this post. There I read the temperature from a tea cup and print it to an SSD1306 OLED display both sharing the same I²C bus.

Where to go from here?

There is much more information and example programs in the crate documentation.
Please give this driver a try and report any issues you may encounter in the issue tracker.
Feedback, suggestions and improvements are gladly welcome.

What’s next?

As I said, I have been writing several platform-agnostic Rust drivers (15 published at the moment) and will announce them here soon.

Thanks for reading and stay tuned!

Links:

Share