i2c temperature sensor code problem tc74a0 5.0vat

Ive been using a tc74a0 for awhile. works great until I started working on my power supply project. I need it to read to at least 100c. currently it only gets to about 45c sometimes a little more sometimes a little less. Ive tried different things and cannot get anything to work correctly
any help is appreciated

#include <Wire.h>

int i2c = 72; // i2c address 
int a = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin(); 
  Serial.println("hello");


}

void loop() {

  Wire.beginTransmission(i2c);

  Wire.write(a);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 1);
  while(Wire.available() == 0);

  int c = Wire.read();
  int f = (c*9.0/5.0 + 32.0);
  Serial.print(c);
  Serial.print("C, ");
  Serial.print(f);
  Serial.println("F.");


  delay(500);
}
  int c = Wire.read();

The Wire.read() method returns a byte. Storing that in an int wastes space.

I need it to read to at least 100c. currently it only gets to about 45c sometimes a little more sometimes a little less.

What makes you think that you have a programming problem?

The TC74, http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010749

As I read the datasheet, the temperature is a signed 8-bit number in the TEMP register.
The Wire.read() returns an unsigned 8-bit number.

unsigned char temp;

temp = (unsigned char) Wire.read();
c = temp;

But your code should have read more than 45 degrees anyway, so perhaps PaulS is right and perhaps your measurement is not correct.

Try this for the loop routine and post the results if you heat the sensor above 45°C:

void loop() {

  Wire.beginTransmission(i2c);

  Wire.write(a);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 2);
  while(Wire.available() == 0);

  int8_t c = Wire.read();
  Serial.print(c);
  Serial.println("C");
  uint8_t config = Wire.read();
  Serial.print("config: ");
  Serial.println(config);

  delay(500);
}
  Wire.requestFrom(i2c, 2);

while(Wire.available() == 0);

Wire.requestFrom returns when there is data, or it cannot get the data. Doing Wire.available afterwards achieves nothing, except possibly to send the program into a loop if no data was returned.

pylon:
Try this for the loop routine and post the results if you heat the sensor above 45°C:

void loop() {

Wire.beginTransmission(i2c);

Wire.write(a);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 2);
  while(Wire.available() == 0);

int8_t c = Wire.read();
  Serial.print(c);
  Serial.println("C");
  uint8_t config = Wire.read();
  Serial.print("config: ");
  Serial.println(config);

delay(500);
}



ok I tried this and now it maxed out at 50c then it stops I reset the board then it starts working again 
One time it got to 51c then froze I reset it as fast as I could and then it started working again at 50c and slowly cooled down?

ok I removed the while(Wire.available() == 0); from the code and something odd happened, it hit 52c then said -1c several times then said 53c then it started cooling off and going back down it would not go over -1c

  while(Wire.available() == 0);

PaulS:

  int c = Wire.read();

The Wire.read() method returns a byte. Storing that in an int wastes space.

I need it to read to at least 100c. currently it only gets to about 45c sometimes a little more sometimes a little less.

What makes you think that you have a programming problem?

how it stalls then works fine after a reset also i tried 2 different sensors so that part is highly unlikely

Erdin:
The TC74, http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010749

As I read the datasheet, the temperature is a signed 8-bit number in the TEMP register.
The Wire.read() returns an unsigned 8-bit number.

unsigned char temp;

temp = (unsigned char) Wire.read();
c = temp;



ok I tried the unsigned char and above 52c it says 255c
unsigned char c = (unsigned char) Wire.read();
  Serial.print(c);

ok I tried this and now it maxed out at 50c then it stops I reset the board then it starts working again
One time it got to 51c then froze I reset it as fast as I could and then it started working again at 50c and slowly cooled down?

OK, but what's the output? I asked you for the output not the temperatures. I wanted the output of the config register at the different temperatures, especially if the temperatures rises over 50°C.

pylon:

ok I tried this and now it maxed out at 50c then it stops I reset the board then it starts working again
One time it got to 51c then froze I reset it as fast as I could and then it started working again at 50c and slowly cooled down?

OK, but what's the output? I asked you for the output not the temperatures. I wanted the output of the config register at the different temperatures, especially if the temperatures rises over 50°C.

ok I didnt know that and im not near the arduino setup but im almost positive it only spit out 255 at the varying temps
Should I make a youtube video and post the link so everyone could see exactly what it is doing?

For me it's enough if you copy/paste the output of the serial monitor to your next post.

it only spit out 255 at the varying temps

For the temperature or for the config value?

BTW: How do you heat the sensor above 50°C?

pylon:
For me it's enough if you copy/paste the output of the serial monitor to your next post.

it only spit out 255 at the varying temps

For the temperature or for the config value?

BTW: How do you heat the sensor above 50°C?

the temp sensor hit a 54c max then said -1c as I heated it then as it cooled when back down
the config always said 255 from when opened serial monitor at 19c then heated it (with a lighter on the metal tab t0-220) up to 52c then -1c then as it was cooling down it started at 54c and downward. I understand why the max varies slightly because of the .5 second delay but it cant be much higher than it has hit

pylon:
For me it's enough if you copy/paste the output of the serial monitor to your next post.

thats what I tried but it will not let me copy only highlight

thats what I tried but it will not let me copy only highlight

Have you tried the keyboard shortcuts (Ctrl-C/Ctrl-V or on the Mac Cmd-C/Cmd-V)? For me they're working perfectly.

it only spit out 255 at the varying temps

Then there's something completely wrong as 6 of the 8 bits must be 0 always (by definition as to the datasheet).

Try that new code, I haven't found in the datasheet if the device is able to read more than one register per transfer, so I put it in a separate transfer.

void loop() {

  Wire.beginTransmission(i2c);

  Wire.write(a);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 1);
  int8_t c = Wire.read();
  Serial.print(c);
  Serial.println("C");
  Wire.beginTransmission(i2c);
  Wire.write(0x01);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 1);
  uint8_t config = Wire.read();
  Serial.print("config: ");
  Serial.println(config);

  delay(500);
}

with a lighter on the metal tab t0-220

Don't you have a softer method of heating the part? I would try a hair dryer, you won't get to 100°C but over 50°C. A lighter puts temperatures of several hundred degrees to the device which might harm it.

pylon:

thats what I tried but it will not let me copy only highlight

Have you tried the keyboard shortcuts (Ctrl-C/Ctrl-V or on the Mac Cmd-C/Cmd-V)? For me they're working perfectly.

it only spit out 255 at the varying temps

Then there's something completely wrong as 6 of the 8 bits must be 0 always (by definition as to the datasheet).

Try that new code, I haven't found in the datasheet if the device is able to read more than one register per transfer, so I put it in a separate transfer.

void loop() {

Wire.beginTransmission(i2c);

Wire.write(a);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 1);
  int8_t c = Wire.read();
  Serial.print(c);
  Serial.println("C");
  Wire.beginTransmission(i2c);
  Wire.write(0x01);
  Wire.endTransmission();
  Wire.requestFrom(i2c, 1);
  uint8_t config = Wire.read();
  Serial.print("config: ");
  Serial.println(config);

delay(500);
}






> with a lighter on the metal tab t0-220



Don't you have a softer method of heating the part? I would try a hair dryer, you won't get to 100°C but over 50°C. A lighter puts temperatures of several hundred degrees to the device which might harm it.

im barely hitting the metal tab and I touch it then pull it off and then touch it then back off
and here is the serial monitor with the new code you posted

hello

19C
config: 64
19C
config: 64
20C
config: 64
19C
config: 64
19C
config: 64
20C
config: 64
19C
config: 64
19C
config: 64
19C
config: 64
19C
config: 64
19C
config: 64
19C
config: 64
19C
config: 64
20C
config: 64
19C
config: 64
19C
config: 64
20C
config: 64
21C
config: 64
22C
config: 64
23C
config: 64
25C
config: 64
27C
config: 64
28C
config: 64
28C
config: 64
29C
config: 64
30C
config: 64
32C
config: 64
33C
config: 64
34C
config: 64
34C
config: 64
34C
config: 64
34C
config: 64
35C
config: 64
35C
config: 64
35C
config: 64
36C
config: 64
37C
config: 64
37C
config: 64
38C
config: 64
39C
config: 64
39C
config: 64
40C
config: 64
40C
config: 64
41C
config: 64
42C
config: 64
42C
config: 64
42C
config: 64
42C
config: 64
43C
config: 64
43C
config: 64
44C
config: 64
44C
config: 64
44C
config: 64
44C
config: 64
44C
config: 64
43C
config: 64
43C
config: 64
44C
config: 64
44C
config: 64
44C
config: 64
44C
config: 64
45C
config: 64
45C
config: 64
46C
config: 64
46C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
48C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
46C
config: 64
46C
config: 64
45C
config: 64
45C
config: 64
45C
config: 64
44C
config: 64
45C
config: 64
46C
config: 64
46C
config: 64
47C
config: 64
49C
config: 64
49C
config: 64
50C
config: 64
52C
config: 64
52C
config: 64
53C
config: 64
53C
config: 64
52C
config: 64
52C
config: 64
52C
config: 64
52C
config: 64
52C
config: 64
52C
config: 64
53C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
53C
config: 53
52C
config: 64
52C
config: 64
52C
config: 64
51C
config: 64
51C
config: 64
52C
config: 64
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 255
-1C
config: 64
53C
config: 64
52C
config: 64
52C
config: 64
51C
config: 64
51C
config: 64
50C
config: 64
50C
config: 64
50C
config: 64
50C
config: 64
49C
config: 64
50C
config: 64
49C
config: 64
49C
config: 64
48C
config: 64
48C
config: 64
48C
config: 64
48C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
47C
config: 64
46C
config: 64

  Wire.requestFrom(i2c, 1);
  int8_t c = Wire.read();

Wire.requestFrom returns how many bytes you received, information you are ignoring. It should read like:

  if (Wire.requestFrom(i2c, 1) != 1)
     {
     // some sort of error handling
     }
  else
    {
    int8_t c = Wire.read();

    // do something with the data
    }

Wire.read is likely to return -1 if there is no data available.

I guess you should change the way you're heating up that poor little sensor. Probably the chip overheats before the heat reaches the temperature sensing element. The metal tab is ground connected and most probably not meant to be heated that way.

pylon:
I guess you should change the way you're heating up that poor little sensor. Probably the chip overheats before the heat reaches the temperature sensing element. The metal tab is ground connected and most probably not meant to be heated that way.

ok ill try it with some hot air at low temp and heat it really slowly

So I do not need the wire.requestFrom(i2c,1) ?