Measure Temperature with TMP102
The TMP102 is an I2C based temperature sensor from Texas Instruments. It has very high resolution. Datasheet
tmp102=0x90 'TMP102 Slave Address
I2CINIT(100000) '100kHz Speed
I2CTIME(10) '10ms timeout
min1=261
max1=-40
REPEAT
a$=I2CRD$(tmp102, 0, 2) 'Get temp
temp=BYTESTR(a$,-2) 'Convert 2 bytes to integer
temp=temp*0.0625/16 'Fix the scale factor
IF temp > 128 THEN
temp = temp - 256 'Sign bit got lost in string to integer conversion
ENDIF
temp4=temp*9/5+32 'Make Farenheit
IF min1 > temp4 THEN 'Find the minimum temperature
min1 = temp4 'New minimum
ENDIF
IF max1 < temp4 THEN 'Save Maximum Temp
max1 = temp4
ENDIF
'Display the measurements in columns
PRINT temp, "C",TAB(15), temp4,"F",TAB(30), "Min ", min1, "F";
PRINT TAB(45), "Max ", max1, "F"
WAIT(5000) 'Repeat every five seconds
x=INKEY
UNTIL x >0 'until the user presses a key
END
Download
tmp102=0x90 'TMP102 Slave Address
I2CINIT(100000) '100kHz Speed
I2CTIME(10) '10ms timeout
min1=261
max1=-40
REPEAT
a$=I2CRD$(tmp102, 0, 2) 'Get temp
temp=BYTESTR(a$,-2) 'Convert 2 bytes to integer
temp=temp*0.0625/16 'Fix the scale factor
IF temp > 128 THEN
temp = temp - 256 'Sign bit got lost in string to integer conversion
ENDIF
temp4=temp*9/5+32 'Make Farenheit
IF min1 > temp4 THEN 'Find the minimum temperature
min1 = temp4 'New minimum
ENDIF
IF max1 < temp4 THEN 'Save Maximum Temp
max1 = temp4
ENDIF
'Display the measurements in columns
PRINT temp, "C",TAB(15), temp4,"F",TAB(30), "Min ", min1, "F";
PRINT TAB(45), "Max ", max1, "F"
WAIT(5000) 'Repeat every five seconds
x=INKEY
UNTIL x >0 'until the user presses a key
END
Download