So awhile back with quite a bit of guidance I was able to get my TMP102 sensors working.
I fired them up again today and have been getting strange results. I’m sure it’s just user error, but I’m not sure where to look.
Here’s my code,
// For the TMP102 sensor
int tmp102Address=0x48;
float celsius = 0;
void setup() {
Spark.variable("temperature",&celsius,DOUBLE);
//Serial.begin(9600);
Wire.begin();
}
void loop() {
float celsius = getTemperature();
}
float getTemperature() {
byte MSB=0;
byte LSB=0;
Wire.requestFrom(tmp102Address,2);
MSB = Wire.read();
LSB = Wire.read();
int16_t TemperatureSum = ((MSB << 8) | LSB) >> 4;
float celsius = TemperatureSum*0.0625;
return celsius;
}
When I run the following:
curl https://api.spark.io/v1/devices//temperature?access_token=
This is what I get back,
{
"cmd": "VarReturn",
"name": "temperature",
"result": 4.090223858389538e-270,
"coreInfo": {
"last_app": "",
"last_heard": "2014-09-14T02:06:43.643Z",
"connected": true,
"deviceID": "<snip>"
}
My question is why am i getting those strange values in result?