3 years, 10 months ago.

Why tmp102 library/example doesn't simply work?

Hi I am trying to read temp from TMP102 sensor using BLE NANO. The sensor works well when used with arduino pro mini and arduino scketch (i2c)

However, when I import TMP102 library program sample into MBED env it does not works.

Need help... Thank you

Alex

Sample program

#include "mbed.h"
#include "TMP102.h"
TMP102 temperature(P0_10, P0_8, 0x90);   //ADD0 pin is connected to ground
int main()
{
    while(1) 
    {
        printf("Temperature: %f\n", temperature.read());
        wait(1.0);
    }
}

Output:
Temperature: 0.000000
Temperature: 0.000000
Temperature: 0.000000
Temperature: 0.000000
Temperature: 0.000000

2 Answers

3 years, 10 months ago.

If you try 0x91 instead, do you get any data back?

I tried 0x91 in 2 different pin labels and got always temperature 0.0000000

TMP102 temperature(P0_10, P0_8, 0x91);

and

TMP102 temperature(p10, p8, 0x91);

posted by Alex Co 05 Oct 2017
3 years, 10 months ago.

Hi, I've used the TMP102 on nRF51822 modules, and I have a slightly different declaration than you, but yours should work too according to the pinnames.h document.

<<code>>TMP102 temperature(p10, p8, 0x90); <</code>>

Maybe you have the actual SDA and SCLK wires from the TMP102 on the incorrect pins on the BLE nano? Are you using the nRF51 version of the BLE nano? If so, p10 (SDA) and p8 (SCLK) corresponds to "CTS" pin and "RTS" pin (respectively) on the Redbear Nano.

It's less confusing if you use p4 and p5 for the I2C. They're not subject to jumper configuration changes.

I also used p10 and p8 definitions but same result (0.00000000) yes, it is based on nRF51 (Ble Nano 1) Yes, I have been using CTS and RTS pins. Please see my schematic in https://ibb.co/m49p8w

But does nRF51 has two I2C engines? Can I use P4 and P5 pins simply passing them on TMP102 temperature(P0_10, P0_8, 0x90); call? Should I change something to use them? Which one is SDA, SCL?

Thanks a lot

Alex

----------

Hi Eric

It works now!!!

I was using another lib (https://os.mbed.com/components/TMP102-Temperature-Sensor/)

When using the lib you proposed and change pins to P4,p5, 0x90 it simply works!

Thanks a lot!

Alex

posted by Alex Co 05 Oct 2017

You can assign the SDA and SCLK pins to pretty much any digital pin you want. It's all in the TMP102 constructor. So, you can do

TMP102 temperature(p4, p5, 0x90); p0.4=SDA, p0.5=SCLK

The first argument always assigns the SDA pin, and the second is SCLK pin.

Just to confirm we're using the same thing, I'm using this library:

https://os.mbed.com/users/chris/code/TMP102/

Also, I notice your pin diagram shows that the TMP102 you have has more than just vcc, gnd, sda, sclk. There's some other pin that you're tied to ground? So my TMP102 is a bit different module than yours.

posted by Eric Tsai 07 Oct 2017