The fost02 is a combined temperature and humidity sensor. It claims to produce up to 12 bit humidity data and 14 bit temperature data, but I have only had success in reading 8 bit humidity and 12 bit temperature data. This sensor is VERY similar to the Sensirion SHT-11. Peter Anderson has a nice write up on this here. Here is some code based on work done by Peter Anderson to read out this sensor with a Picaxe:
‘ pin definitions
Symbol SCK = OutPut0
Symbol SDAOut = Output1
Symbol SDAin = Input1
Symbol shtMT = %00000011 ‘ Meas Temp
Symbol shtMH = %00000101 ‘ Meas Rel Hum
Symbol shtSRW = %00000110 ‘ Status Reg Write
Symbol shtSRR = %00000111 ‘ Status Reg Read
Symbol shtRSR = %00011110 ‘ Soft Reset
Symbol OByte = B0
Symbol IByte = B0
Symbol N = B1
Symbol H = B0
Symbol L = B1
Symbol SOrh = W1
Symbol SOt = W2
Symbol Scratch = W3
Symbol RH_100 = W5
Symbol MSBit = B12
Main:
Top:
‘ soft reset
GoSub Idle
GoSub ResetComm
GoSub TransStart
OByte = shtRSR
GoSub WriteByte
Pause 50
‘ measure the temperature
GoSub Idle
GoSub ResetComm
GoSub TransStart
OByte = shtMT
GoSub WriteByte
Pause 250
Pause 250
GoSub ReadByte ‘ read high byte
SOt = IByte * 256
GoSub ReadByte ‘ read low byte
SOt = SOt + IByte
‘Temp = SOt * 0.04 – 40
SOt = SOt * 4
H = SOt / 100 -40
L = SOt % 100
SerTxD (“T = “,#H,”.”,#L,13,10)
‘ measure the humidity
GoSub Idle
GoSub ResetComm
GoSub TransStart
OByte = shtMH ‘ measure humidity
GoSub WriteByte
Pause 250 ‘ allow for conversion to complete
Pause 250
GoSub ReadByte
SOrh = IByte * 256
GoSub ReadByte
SOrh = SOrh + IByte
‘ Do the calculations
‘RH_100 = 0.648 * SOrh – 4 – 0.00072 * SOrh^2
Scratch = SOrh *6 / 10
Scratch = Scratch * 4 / 100 + Scratch
Scratch = Scratch * 8 / 1000 + Scratch
RH_100 = Scratch – 4
Scratch = SOrh *SOrh / 10000 *7
Scratch = Scratch *2 / 100000 + Scratch
RH_100 = RH_100 – Scratch
SerTxD (“RH = “,#RH_100,13,10)
GoTo Top
Idle:
Low SCK ‘ low clock
High SDAOut ‘ high Z on Data
Return
ResetComm:
Low SCK ‘ low on SCK
High SDAOut ‘ DTA in high Z state
For N = 1 to 9
High SCK
Low SCK
Next
Return
TransStart:
High SDAOut
Low SCK
High SCK
Low SDAOut
Low SCK
High SCK
High SDAOut
Low SCK
Return
WriteByte:
For N = 1 to 8
MSBit = OByte / 128
If MSBit = 1 Then WriteByte_1
Low SDAOut
Goto WriteByte_2
WriteByte_1:
High SDAOut
WriteByte_2:
High SCK
Low SCK
OByte = OByte * 2
Next
High SDAOut
High SCK
Low SCK
Return
ReadByte:
High SDAOut
IByte = $00
For N = 1 To 8
High SCK
IByte = IByte * 2 + SDAIn
Low SCK
Next
Low SDAOut
High SCK
Low SCK
High SDAOut
Return