/*
  TMP102 Example Code
  Updated 14 May 2012 by Noah Crowley

  Based on:
    http://bildr.org/2011/01/tmp102-arduino/
    2011 bildr
    Released under the MIT License - Please reuse change and share
    Simple code for the TMP102, simply prints temperature via serial
*/


#include <Wire.h>

//The TMP102 has an address pin which can be used to change the I2C address
//of the sensor. In this example, that pin is tied to ground, which results
//in the sensor using an address of 72, or 0x48 in hexadecimal.
int tmp102Address = 0x48;

void setup(){
  Serial.begin(9600);
  Wire.begin();
}

void loop(){
  float celsius = getTemperature();
  Serial.print("Celsius: ");
  Serial.println(celsius);

  delay(1000); //Delay for one second. You can remove this.
}

float getTemperature(){
  Wire.requestFrom(tmp102Address,2);

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  return celsius;
}