Help with interfacing and reading out data from TMP275 to arduino

Hey there, I am using a TMP275 sensor that I have connected with Arduino. The pin connection are as followed: -

TMP275 - Arduino
SCL - SCL
SDA -SDA
Vcc - 5V
GND - GND
A0-A2 - GND

I have written the following code to obtain the data from the sensor:-

#include <Wire.h>
#define break_out_config 0x48// standard breakout configuration of TMP275
#define temperature_register 0x00 // standard register of temp sensor

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  double temp = sensorRead();
  Serial.print("Temperature detected is:");
  Serial.print(temp);
  Serial.println(" Celsius");
  delay(500); // value presented in every 30 sec
}

double sensorRead(void){
  // temp hold 2 bytes of data read back from TMP275
  uint8_t temp[2];

  // tempc will hold the modifies combination of the bytes
  int16_t tempc;

  // pointing to the device (sensor)
  Wire.beginTransmission(break_out_config);

  // Pointing to the temperature register
  Wire.write(temperature_register);

  // Removing the master control to the Sensor
  Wire.endTransmission();

  // Requesting the temperature data
  Wire.requestFrom(break_out_config,2);
//  Serial.print("Code runs till here ");
  // Checking if 2 bytes are returned 
  if (Wire.available() <= 2){
    // reading out the data 
    temp[0] = Wire.read();
    temp[1] = Wire.read();

    // ignore the lower 4 bits of byte 2 
    temp[1] = temp[1] >> 4;
    // combining to make one 12 bit binary number
    tempc = ((temp[0]<<4|temp[1]));
    // Converting the temperature to celcius(0.0625 oC resolution) and return
    return tempc*0.0625;
    }
 }
 }

I have got pull-up resistors attached to SCL AND SDA as mentioned in the datasheet.
The code uploads fine. But I obtain a constant temp= 255.94 oC in the serial monitor. What seems to be wrong?

What do you see if you print out the individual bytes?
Maybe your "endian" is backward.
What temperature is expected?

I am trying out of sensor at room temp so a temperature of 25-27 oC is expected. Currently prototyping and testing out the sensor.

I obtain 15.94 oC when printing temp[0] and 0.94 when printing temp[1] individually. They are not varying either.

Thanks for the quick reply though :slight_smile:

Well, Anyhow the sensor was damaged. I checked the I2C transactions via an oscilloscope and it got confirmed that the sensor was damaged. While trying the same code and connection setup with another TMP275 sensor. It worked like a charm.
Facing this error, Some of my suggestions if you run yourself with such an error:

  1. Always let the first step when trying I2C communication be to check the address of the sensor using the I2C_scanner sketch already available in Arduino. It will tell you if it has detected a sensor or not.
  2. Check for the I2C transactions using an oscilloscope(if available) and ask someone who has worked with them before to verify if they are generic or not.
  3. Try using another sensor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.