Difference between revisions of "Temp sens.c"

From eLinux.org
Jump to: navigation, search
 
Line 1: Line 1:
 +
Grab hold of a "Microchip TC74" temperature sensor IC, a TO220 is easy to handle, and hook it up to the bus using the pins as shown in the hardware hack section. Make sure you use a 3.3v part.
 +
 
* http://ww1.microchip.com/downloads/en/devicedoc/21462c.pdf
 
* http://ww1.microchip.com/downloads/en/devicedoc/21462c.pdf
 +
 +
 +
<code><pre>
 +
#include <stdio.h>
 +
#include <fcntl.h>
 +
#include <sys/ioctl.h>
 +
 +
 +
#define I2C_DEVICE  "/dev/i2c/0"
 +
#define I2C_SLAVE  0x0703
 +
 +
//Whats the temperature
 +
 +
void printtemp()
 +
{
 +
char dbuff[10];
 +
 +
//***TEMPERATURE
 +
 +
i2c_read (0x48, dbuff, 1);
 +
 +
printf ("Temperature :- %d degrees C\n", dbuff[0]);
 +
}
 +
 +
int main(void)
 +
{
 +
printtemp();
 +
 +
return 0;
 +
 +
}
 +
 +
 +
</pre></code>

Revision as of 06:46, 22 May 2007

Grab hold of a "Microchip TC74" temperature sensor IC, a TO220 is easy to handle, and hook it up to the bus using the pins as shown in the hardware hack section. Make sure you use a 3.3v part.


#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>


#define I2C_DEVICE  "/dev/i2c/0"
#define I2C_SLAVE  0x0703

//Whats the temperature

void printtemp()
{
	char dbuff[10];

	//***TEMPERATURE

	i2c_read (0x48, dbuff, 1);

	printf ("Temperature :- %d degrees C\n", dbuff[0]);
}

int main(void)
{
	printtemp();

	return 0;

}