TMP102 and Spark

Hi @brettg98

The pull-ups for i2c are pretty easy! You need two resistors with a value of between 1k and 10k each, with 4.7k ohm being ideal and you need to connect one from pin D0 to 3V3 and the other from pin D1 to 3V3.

If you look at the fritzing diagram in this post above:

The would go from D0 to the positive 3v3 rail at the very bottom and from D1 to the same 3v3 rail at the bottom.

@bko thanks! With a little help from a co-worker I got it working. I’m going to play around with Fritzing a little and see if can provide an updated diagram for other novices like myself.

1 Like

hmmm…seems that I spoke to soon. Was working fine and I was wandering around the house and outside watching the temperature fluctuate, now I’m back to 255.94…no clue why it would stop working.

Loose connection somewhere? Are you breadboarding or soldering?

I decided to try it on my other core. Rewired the breadboard and flashed the core and it seems to be working again?? I’m sure that it’s user error, but I’m not sure how to troubleshoot.

I’ve included a few pictures.

First, how I have my pull-ups wired

Second, how I have my sensor wired

Hi @brettg98

The pictures really help! So you TMP102 board from Sparkfun has plated thru-holes for the connections–did you solder those jumper wires into those holes or are they just press fit?

I think your problem could be those connections to the TMP102 breakout board! Those really need to be soldered to be reliable connections.

[edit] You could solder headers like a lot of prototype boards have. If you have the Maker Kit, it has them-you just cut them to the length need with diagonal cutters on the plastic between pins.

Hi @bko,

Right now they are just press fit. Do you think what I’m seeing is just a result of a flaky connection?

Should I be soldering something like this to the sensor and then connecting it to my breadboard?

So as I was typing the last message the sensor started returning 255.94 again. I’ll do some soldering and let you know.

1 Like

Hi @brettg98

Yes those are the headers I was talking about from Sparkfun.

You can solder any wire in there for prototyping, even the breadboard wires. The headers are nice since it makes it breadboard friendly and you can use them later for a permanent installation too.

I really think you will see the reliability improve dramatically!

Of course. This seems to work with my sensor (it’s the old sparkfun board). I’ve changed the code below to also publish the temperature using the new Spark.publish() API

//////////////////////////////////////////////////////////////////
//(c)2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial
// edited by m01
//////////////////////////////////////////////////////////////////
#include <application.h>
int tmp102Address = 0x48; // 0x90; //0x48;
double celsius=0;
byte MSB=0;
byte LSB=0;

char tmp[10];
const int interval = 60; // seconds

float getTemperature();

#define USE_SERIAL 0

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

#if USE_SERIAL == 1
    Serial.begin(9600);
#endif
    Wire.begin();
    memset(tmp, 0, sizeof(tmp)/sizeof(*tmp));
}

void loop(){

    celsius = getTemperature();
    sprintf(tmp, "%.2f", celsius);
    Spark.publish("c0-temperature", tmp, interval);

#if USE_SERIAL == 1
    Serial.print("Celsius: ");
    Serial.println(celsius);
#endif
    delay(interval * 1000);
}

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;
}

Sample:

% curl "https://api.spark.io/v1/devices/<snip>/temperature?access_token=<snip>"
{
  "cmd": "VarReturn",
  "name": "temperature",
  "result": 24.6875,
  "coreInfo": {
    "last_app": "",
    "last_heard": "2014-04-26T20:42:22.118Z",
    "connected": true,
    "deviceID": "<snip>"
  }
}

The publishing doesn’t seem to work right now, but it definitely used to and I didn’t change the code, so not sure what’s going on there.

Hi @m01

Thanks for sharing that code–glad it is working for you!

One small point that I have seen a lot–since int is 32-bits on Spark and only 16-bits on Arduino, you need to change this:

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

to this

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

If you want to have positive and negative temperatures.

@bko thanks for all the guidance on this…really appreciate the help!

So I did some soldering tonight (attached a picture of a newbie soldering) and you’re right it seems to be working. I’ve setup the script to send every 30 seconds for testing purposes. So far so good - no 255.

One last question - do you have any suggestions on an affordable soldering setup? I picked one up at the local electronics place and it smokes badly and the handle heats up way too much!

Hi @brettg98

I am so glad the TMP102 is working better for you! You did a nice job soldering too!

So I have Weller soldering gear but it is not what I would call affordable. There are soldering irons that have no temperature control (sounds like you have one of those) and irons where the temperature control is built-in to the tip of the iron and you change tips to change temps, and there are the irons I like where there is a just knob you turn to set the temp. The nicer ones start at around $100 and go up.

You can get an off-brand soldering iron like this one at Sparkfun for around $50:

Sparkfun also sells Hakko’s which are nice for around $100, but they are so popular they are often out of stock.

Thanks @bko for the advice re: 16 & 32 bit ints!

Sorry if it’s not the main topic, but i’m looking for a breakout (or a not-smd chip) for temp sensors with I2C, without internal pullups. I’ve already i2C devices (mcp23008, lcd display) with 4.7K pullups.

Theses chips a really tiny, and hand soldering is a nightmare.

The sparkfun includes pullups.

@ticoli, you can always remove the resistors using a fine tipped soldering iron :grinning:

1 Like

@peekay123 That’s what i have in mind.
I’m not alone: http://electronics.stackexchange.com/questions/68096/how-to-deal-with-multiple-pull-up-resistors-on-modules/

Why do the hell they include pullup? I really do not understand? Most of I2C users are using only one device on the bus?

@ticoli , some vendors have cut-away traces to take the pull-ups out. I wish they were all like that.

1 Like