Author Topic: Digistump Oak with TMP102 temperature sensor  (Read 9859 times)


  • Jr. Member
  • **
  • Posts: 64
Digistump Oak with TMP102 temperature sensor
« on: March 26, 2017, 08:53:46 am »
Below, a simple circuit and code for the TMP102 temperature sensor with an Oak - and why you might want to use one.

There are easier options. One, using a thermistor and a voltage divider, I do not recommend, given the Oak's (and ESP8266's) wonky and inaccurate analog pin. See,2576.0.html.

A thermistor can work well if you're adding analog pins anyways, i.e. using an ADS1015 or ADS1115 ADC device, but is not worth the bother or the somewhat lower accuracy otherwise.

The one-wire approach using the Dallas DS18B20 is clean and easy, and requires only one pin for interfacing. It works across a wide temperature range (-55 to 125°C or -67F to 257F), and is accurate to 0.5°C or 0.3F. Additionally, Digistump offers a nice little shield plus tutorial plus code at

There would rarely be a need for something (slightly) larger, more expensive and more complicated like the TMP102. Why bother?

You're out of digital pins. Too many devices already connected to the Oak, including to the I2C bus. Fortunately, the TMP102 happily shares this bus with others, so in this case, rather than giving up two pins, it can connect to an existing circuit without using any new ones.

The TMP102 operating temperature range is slightly broader (-55 to 150°C or -67F to 302F) and it sports a precision of better than 0.1°C, though without precision calibration its accuracy is the same 0.5°C as cited for the DS18B20. I doubt this would matter in most cases.

More importantly, the TMP102 uses considerably less power: 10 µA when active, and less than 1 µA in sleep mode, compared to the DS18B20's 4 mA sink current and another 1 mA when active - a 500x difference when active, and 4000x in sleep. Given that a non-transmitting Oak might draw some 15-50 mA under load, 1 mA in sleep, and as low as 50 µa in deep sleep, the DS18B20 could help suck a battery dry pretty quickly in an otherwise optimized system.

Fritzing diagram for the Digistump Oak with TMP102:

Note: I haven't used the ALT (temperature alarm trigger) and ADD0 (define an alternate I2C address) pins.

The code is a minimalist implementation of SparkFun's TMP102 library that publishes the measured temperature to Particle once per second. I did find that I needed to initialize the device by uncommenting the code where indicated before it would work properly. I recommend recommenting this code or deleting it after the first run - faster, saves on compiled code, and less wear on the TMP102.

Code: [Select]
#include <Wire.h> // Used to establied serial communication on the I2C bus
#include "SparkFunTMP102.h" // Used to send and recieve specific information from our sensor

float temperature;
TMP102 tempSensor(0x48); // Initialize sensor at I2C address 0x48

void setup() {
  tempSensor.begin();  // Join I2C bus

//use the following once only - these settings are saved to the TMP102 sensor and remain even after power-off
  // set the number of consecutive faults before triggering alarm.
  // 0-3: 0:1 fault, 1:2 faults, 2:4 faults, 3:6 faults.
  sensor0.setFault(0);  // Trigger alarm immediately
  // set the polarity of the Alarm. (0:Active LOW, 1:Active HIGH).
  sensor0.setAlertPolarity(1); // Active HIGH
  // set the sensor in Comparator Mode (0) or Interrupt Mode (1).
  sensor0.setAlertMode(0); // Comparator Mode.
  // set the Conversion Rate (how quickly the sensor gets a new reading)
  //0-3: 0:0.25Hz, 1:1Hz, 2:4Hz, 3:8Hz
  //set Extended Mode.
  //0:12-bit Temperature(-55C to +128C) 1:13-bit Temperature(-55C to +150C)

  //set T_HIGH, the upper limit to trigger the alert on
  //sensor0.setHighTempF(85.0);  // set T_HIGH in F
  sensor0.setHighTempC(29.4); // set T_HIGH in C
  //set T_LOW, the lower limit to shut turn off the alert
  //sensor0.setLowTempF(84.0);  // set T_LOW in F
  sensor0.setLowTempC(26.67); // set T_LOW in C


void loop()
  temperature = tempSensor.readTempC();

  delay(1000);  // Wait 1000ms