TMP102 and Spark

I am trying to use a TMP102 temperature sensor with Spark and I dont seem i can make it work.

I am using the buildr tutorial:

http://bildr.org/2011/01/tmp102-arduino/

I connected in the same way as it is described there and used the code. (of course with some modifications - no function for calculating temp - it runs into loop) I want to put the output on a Serial 7 Segment display. I have no problem in writing the output there, but i dont seem to have good readings from the I2C sensor.

Is there any other way to connect the sensor to SparkCore or the problem is with the software?

Are you using that Sparkfun Breakout board, or something else? The Sparkfun board has built-in pullup resistors for the SDA and SCL lines.

If you are using something else, it may not have the pullups, so I suggest adding them. 4K7 will do.

Could you elaborate on this? Are the reading fluctuating or simply dead?

Thanks!

I am using the SparkFun breakout board.

I am reading the value with the example provided by SparkCore over internet. (with a get request).

I have the value 2075 and it is not rising or going down depending on the temperature.

I haven’t figured how to see the value over Serial on the PC yet,

So do you know for sure that the problem is with the sensor and not with the firmware code etc? If you deliberately assign a different value (eg. 12345) to the same variable in firmware, overwriting the value from the sensor, do you see that new value when read over the internet?

Do you have an Arduino you could use to test the sensor?

I have tried assigning values to the variable and it is shown correct.

The sensor is working with Arduino.

I am interested to know if someone has an example of an working I2C sensor connected to Spark Core.

I have not yet, but my core will arrive soon (maybe today!) and I have an i2C sensor. Its a BMP085 which measures atmospheric pressure and temperature. I have it working correctly with Arudino. I will try that with the Spark Core. However, I will have some learning and configuring to do first - you are a little way ahead of me at the moment!

Do you have any other i2C devices to try? an RTC perhaps?

2 Likes

Try using 0x90 as the address when calling Wire.requestFrom.

Hi,

I have the same problem with the TMP102, running at the Spark Core it always return the same value “result”: “255.94”, using the sensor at the Arduino it have a correct value.

I tried the daves​panton suggestion that use the address 0x90 but the result is the same, anyone have any idea about it?

Best regards,

Hello,
I have the exact same problem. The value returned is always 255.94. However the same code with same board is working with my old Arduino.
I have tried both 0x48 and 0x90 to no avail.

Hi,

I found my mistake and I think that will help all, the Spark have a different SDA and SCL pins, you need to turn the TMP102 like below:

D0: SDA (Serial Data Line)
D1: SCL (Serial Clock)

With the address 0x48.

Regards,

Should look like this :wink:

Image made with: Fritzing for Spark Core

Project file here: https://github.com/technobly/SparkCore-Fritzing/raw/master/projects/TMP102/TMP102.fzz

No pull up resistors needed, as the TMP102 has 1k pull-ups already. 3.6V max on V+!

If you connect ADD0 pin to ground, the 7-bit address is 0x48, but the Spark Core currently uses 8-bit addressing so change the address to 0x90. Important that ADD0 is grounded though, or the address changes.

1 Like

Yes the circuit is pretty basic. And it is working when connected to the Arduino. But I can't get anything from the Spark. I tried both 0x48 and 0x90, behavior seems to be the same. Serial returns "Celsius: 255.94
".

Here is my code, anything different in yours, Marcio?

//Arduino 1.0+ Only

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial
//////////////////////////////////////////////////////////////////

int tmp102Address = 0x90; //0x48;
float celsius=0;
byte MSB=0;
byte LSB=0;

void setup(){
Spark.variable("temperature", &celsius, INT);
Spark.variable("LSB", &LSB, INT);
Spark.variable("MSB", &MSB, INT);

Serial.begin(9600);
Wire.begin();
}

void loop(){

celsius = getTemperature();
Serial.print("Celsius: ");
Serial.println(celsius);

delay(1000); //just here to slow down the output. You can remove this
}

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

MSB = Wire.read();
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;
}

Just to say that the problem has been solved today after the firmware update for I2C (link to timb’s post). I can now use adress 0x48 to adress the TMP102.
The only problem remaining is to export the data through spark.variable. I can get it with a string but not a double… Still some way to go!

Fabien, to format you can do something like this:

char temperature[5];

void setup(){
....
Spark.variable("temperature", &temperature, STRING);
}

void loop(){
...
float celsius = getTemperature();

sprintf(temperature, "%.2f", celsius);
...
}

I tried to use your code with the TMP102 breakout board, and I was seeing the same 255.94 issue.

I followed the instructions on these pages to manually build the firmware including the app code posted by Fabien (put it into src/application.cpp). Here are the changes I had to make to it work:

// add:
#include <application.h>
// and a forward declaration for:
float getTemperature();
// and use this address:
int tmp102Address = 0x48;
//also, change:
float celsius=0;
// to:
double celsius=0;
// and update the datatype in:
Spark.variable("temperature", &celsius, DOUBLE);

Thank you all for posting useful hints in this thread!

EDIT: I was earlier suspecting that the cloud IDE was giving me the v0.1.0 firmware rather than 0.2.0, but now I’m not sure that was the case.

Hey m01,

Would you mind posting your updated code? I’m struggling with the same problem and am still getting 255.94 as the return value.

Thanks,

Hi @brettg98

I just wanted to make sure you have pull-ups on your TMP102 i2c lines. If you are using the Sparkfun breakout board, it has them built-in, but other boards might not. Another thing to check is the i2c address jumper.

The value you are getting makes me think that you are not transferring any data.

One other quick point:

int TemperatureSum = ((MSB << 8) | LSB) >> 4;

can produce negative numbers on Arduino but not on Spark due the the 16-bit versus 32-bit integers. A better way would be:

int16_t TemperatureSum = ((MSB << 8) | LSB) >> 4;

Hi @bko,

Thanks for the reminder. I’m using the breakout board that came with the spark.io devices. I do have a Sparkfun version so maybe I’ll give it a try on that board just to see.

Brett

Hi @bko,

So I’ve tried to add the pull-ups, but I’m still having the same issue. Is there a good tutorial on how to use pull-ups? I’m sure that this is just user error, I’m pretty much a newb.

Thanks,