11 years, 2 months ago.

i get 0degree out of my temp sensor

Hi, I cannot read anything from the TMP102, i tried with the example code and this gave nothing. I made my own code:

#include "mbed.h"

Serial pc (USBTX, USBRX);

I2C i2c (p9, p10);  

const int addr = 0x90; 


int main() {

char send[1];

send[0]=0;   //sending the pointer adres to temperature register

char ontvangentemp[2];  //want 2 bytes of information in

while(1){

i2c.write(addr, send, 1, 0);

i2c.read(addr, ontvangentemp, 2, 0);  

pc.printf("test voor TMP102_nieuw1\n\r");

pc.printf("\n\r the temperatuur is %d , %d", ontvangentemp[0], ontvangentemp[1]);

} 

}

The first time i got "test .... the temperatuur is 0, 128), the next times i always get 0,0. how come? i know this will not be the right temperature because i still have to do some conversion Next problem is, most of the time when i push on the button nothing happens in hyperterminal, and then suddenly they come with 10 at the time and i dont see a relation when it happens. anybody has an idea, thanks in advance

fixed

posted by Adriaan Van Steendam 07 Mar 2013

2 Answers

11 years, 2 months ago.

Do you have pull - up resistors on SDA & SCK ??

and are the wires the correct way around.

somewhear between 2K2 & 7K5, to 3V3.

I dont have TMP102, so no more advice.

Ceri

11 years, 2 months ago.

Hi,

I have the solution for hyperterminal. You need to flush the stdout everytime you write a printf, otherwise it is printing when the buffer is full of data. Flush is not a member function of pc. But you also don't need the pc infront of a printf. Only for changing the baud rate of pc, there is an explicit call of the member function needed!

Serial pc (USBTX, USBRX); // USB Virtual Serial Port
...
int main()
{
pc.baud(9600); // changing baud
...
printf("Hello World"); // write some characters
fflush(stdout); // flush the stdout
...
error(""); // Blue Lights of Death
...
}

There is also a second solution. End a printf with a \n character. In my opinion this is not a safe solution, but used in the hole mbed world.