Hey guys. I am just learning to use I2C and the Wire library and am starting with the Microchip TC74 temperature sensor. It has 2 registers. One is a config register which allows you to put the sensor into a low-power standby mode. The other is the temperature reading output as 8 bits in degrees Celsius.
Board: Arduino Uno Rev. 3
Sensor Part #: TC74A0-5.0VCT and TC74A2-5.0VCT
Packaging: TO-220 (through-hole)
Sensor datasheet link: Microchip TC74 Datasheet
Note that right now I am in a cold area with with temps ranging from 0 to 32 deg F (-17 to 0 deg C) and I'm measuring the temps in my room with the heat off.
I have everything connected on a breadboard (so I've considered parasitic capacitance as a possible issue). Connecting SDA to pin A4 and SCL to pin 5, I'm able to get readings on the Serial Monitor. I get readings around 22-24. That translates to ~75 deg F which unless I've got mad cow disease is a reading much higher than expected.
Remember I'm brand new to I2C and Wire so if it ends up being something dumb then please excuse my dumbness . Also forgive me as it's my 1st post to these forums
Here is a list of all the things I've tried and have not fixed the issue:
- I have a 4.7k pull-up resistor on both the SDA and SCL lines
- I have a 0.1uF film capacitor for decoupling at the sensor's VDD pin
- I have tried using both 5.0V and 3.3V as VDD. For some reason, the reading goes up by ~4 degrees when using 3.3V which is even worse
- I initially used TC74A0-5.0VAT and assumed I may have damaged it or it just isn't working. I bought TC74A2-5.0VAT, which has a different address, but nothing changed.
- The TC74 datasheet shows a limit clock speed of 100 kHz, therefore I added Wire.SetClock(10000);
- I increased the delay between readings to as much as 5 seconds
- Pg. 9 of the datasheet shows all the addresses for the the respective temperature part #'s. I have tried all of these addresses, including the default address it gives.
- Yes, I even made sure the sensor was oriented properly and not backwards
#include <Wire.h>
int reading = 0;
int address = 77; //refer to pg. 9 in the datasheet
//TC74A0-5.0VCT --> 1001 000 --> 72
//TC74A1-5.0VCT --> 1001 001 --> 73
//TC74A2-5.0VCT --> 1001 010 --> 74
//TC74A3-5.0VCT --> 1001 011 --> 75
//TC74A4-5.0VCT --> 1001 100 --> 76
//TC74A5-5.0VCT --> 1001 101 --> 77
//TC74A6-5.0VCT --> 1001 110 --> 78
//TC74A7-5.0VCT --> 1001 111 --> 79
void setup() {
Wire.begin();
Serial.begin(9600);
Wire.setClock(10000);
Wire.beginTransmission(address);
Wire.write(byte(0x01));
Wire.write(byte(0x00)); //This points to the config register and writes to it to ensure it is in normal mode and not standby mode
Wire.endTransmission();
delay(150); //delay between transmissions
Wire.beginTransmission(address);
Wire.write(byte(0x00)); //Point to the temperature register to prepare for a reading
Wire.endTransmission();
}
void loop() {
Wire.requestFrom(address,1);
if (Wire.available() == true) {
int AvailableBytes = Wire.available();
Serial.print("Bus available! Available bytes: ");
Serial.println(AvailableBytes);
reading = Wire.read(); //Temp reading in degrees Celsius as a decimal
Serial.print("Temp reading: ");
Serial.print(reading);
Serial.print(", ");
Serial.println(reading,BIN); //Temp reading in degrees Celsius in binary
}
else {
int AvailableBytes = Wire.available();
Serial.print("Bus NOT available! ");
Serial.print("Temp reading: "); // print the reading (though probably pointless as Wire.available() == false)
Serial.print(reading);
Serial.print(", ");
Serial.println(reading,BIN);
}
delay(1000); //delay in between readings
}