TMP102 Sensor

Hi,

I see in the hookup guide for the TMP102 sensor that there are a lot of configurations that can be applied. I was wondering if this sketch is sufficient and would print the temperature reading without any of the configurations?

#include <Wire.h> // library for I2C connection
#include <SparkFunTMP102.h>  // library for temperature sensor

TMP102 sensor;

void setup() {
  Serial.begin(115200);

  while (!Serial);

  Wire.begin();
  
  if(!sensor.begin()) {
    Serial.println("Cannot connect to TMP102.");
    Serial.println("Is the board connected? Is the device ID correct?");
    while(1);
  }
  
  Serial.println("Connected to TMP102!");
}

void loop() {
  float temperature;

  temperature = sensor.readTempF();

  Serial.println(temperature);

  delay(1000);
}

Looks good to me!
Your code should:

  1. Initialize the sensor with sensor.begin()

  2. Read temperature in Fahrenheit with sensor.readTempF()

  3. Print it to the Serial Monitor every second (1000msec)

The only thing you might want to add (optional) is a label so the output is more clear:

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °F");

The configurations mentioned in the hookup guide (alert mode, conversion rate, extended mode, etc.) are optional advanced features you’d only need if you want to something fancy like:

  • Set up temperature alerts/alarms

  • Change the sampling rate

  • Put the sensor in low-power mode

  • Measure temperatures beyond the standard range