PDA

View Full Version : SHT_75 with picbasic pro



iw2fvo
- 27th November 2010, 17:40
Good day to all of you !

I am going to interface the temperature _ humidity sensor type SHT_75 fron Sensirion to the Pic micro.
I will like to know if there is a pic basic pro code to read this sensor and the routines to compute:
> temperature in C having + and - signs
> temperature compensated RH ( + lin too !) in %
> dew point in C having + and - signs
Thanks in advance for any assistance.
Best regards,

Ambrogio

mackrackit
- 28th November 2010, 01:09
Never used on, but a quick lppk at the data sheet makes me think I2C or SHIFTIN might work.
Here is a little about both for working with an EEPROM, maybe it will get you started?
http://www.picbasic.co.uk/forum/content.php?r=165-Serial-EEPROM-Part-1

iw2fvo
- 28th November 2010, 15:36
Good day to all of you ,

I am going to interface the Sensirion SHT_75 Temperature_Humidity sensor to my pic micro.
I would like to know how to compute the RH termally compensate and how to compute the dew point. I rerad Srh @12 bit and St @14 bit.
I expect that the RHtc will range from 0 to 99% RH
The dew point temperature in C will have the sign ( + or - ).

I thank you in advance for any assistance on the coding .

regards,
Ambrogio
IW2FVO

ScaleRobotics
- 28th November 2010, 15:57
A quick google search got me to here for some basic stamp code. It may help. You could also search sht75 on this site for some more hits.

http://www.emesystems.com/OL2sht1x.htm

Please don't double post. I moved your post to this thread, even though it is pretty much the same as the first post.




'{$STAMP BS2}
' SHT15.bs2 version C
' (c) 2002, 2004 Tracy Allen, http://www.emesystems.com
' access the Sensirion model sht11 or sht15
' humidity and temperature chip
' temperature to xx.x degrees Celsius, RH to xx.x %
' Repeatedly shows raw data and converted values on debug screen.
' version B, corrects glaring error in humidity computation
' also adjusts timeout to allow use with faster stamps too.
' version C updates the math for temperature compensation of %RH
' and enables display of negative temperatures
' hookup sht11 or sht15 as follows for this program
'
' STAMP SENSIRION
' 220
' p1 ----o-----/\/\---o--pin 3 sck, clock
' |
' ;---/\/\-----' pull-down
' | 4.7k
' Vss--o-o---------------pin 1 common
' |
' === 0.1uf
' |
' Vdd--o-o---------------pin 4 +5 volts
' | 4.7k
' '---/\/\-----; pull-up
' |
' 220 |
' p0 ----------/\/\---o--pin 2 dta, data
'
'
' The following code does not implement the CRC checking


sck PIN 1
dta PIN 0 ' note, 5k-10k pull-up, also 330ohm between the dta on stamp to dta on sht
dtain var in0

shtTR CON 3 ' read temperature
shtRH CON 5 ' read humidity
shtSW CON 6 ' status register write
shtSR CON 7 ' status register read
shtS0 CON 30 ' restore status register defaults (be sure to delay 11 milliseconds)

cmd VAR Byte
result VAR Word ' raw result from sht, also used as counter
r0 VAR result.byte0
r1 VAR result.byte1
degC VAR Word ' degrees Celsius * 100
RH VAR Word ' %RH * 10
RHtc VAR Word ' for temperature compensation of RH

initialize:
outs=0
dirs=%1111111111111101
GOSUB shtrst ' reset communication with sht

DO
getTemperature:
cmd=shtTR ' temperature command to sht
GOSUB shtget16
degC=result+5/10-400 ' from 100ths to 10ths of a degree with rounding
DEBUG tab,REP "-"\degC.bit15,DEC ABS degC/10,".",DEC1 ABS degC
getHumidity:
cmd=shtRH ' humidity command to sht
GOSUB shtget16
RH=(26542-(54722**result+result))**result-40
' temperature compensation follows:
RHtc=655+(result*5)+(result**15917) ' intermediate factor
RHtc=(RHtc**(degC+2480))-(RHtc**2730)+RH ' compensated value
DEBUG tab, DEC result,tab,"%RH=",DEC RH/10,".",DEC1 RH
DEBUG tab,"%RHtc=",DEC RHtc/10,".",DEC1 RHtc,cr
PAUSE 1000
LOOP

' initializes communication with sht
shtRst:
SHIFTOUT dta,sck,lsbfirst,[$ffff\16]
RETURN

' get 16 bits of data, enter with command in "cmd"
shtget16:
gosub shtcmd ' send the command "cmd"
gosub shtwait ' wait for command to finish
shiftin dta,sck,msbpre,[r1] ' msbyte
low dta ' acknowledge
pulsout sck,10
input dta
shiftin dta,sck,msbpre,[r0] ' lsbyte
input dta ' terminate communication
pulsout sck,10
return

' send start sequence and command
shtcmd:
shtStart: ' send the start sequence
' dta: ~~~~~|_____|~~~~~~
' sck: ___|~~~|_|~~~~|____
' while dta is low, clock goes low and then high
input dta ' pullup high
high sck
low dta
low sck
high sck
input dta
low sck
shtcmd1: ' send the command
shiftout dta,sck,msbfirst,[cmd]
input dta ' allow acknowledge
pulsout sck,10
return

shtWait:
' wait for sht to pull data pin low
' or for time out
result=4096
DO
result=result-1
LOOP WHILE dta & result.bit11
RETURN

</pre>

iw2fvo
- 28th November 2010, 17:49
Thanks mackrackit:
I do not have any problem to talk with the SHT_75.
I am able to get signed temperature tto.
My problem is to compute RHtc with picbasic pro and to compute DEW POINT with its sign.
Thanks for help
Ambrogio
IW2FVO


Never used on, but a quick lppk at the data sheet makes me think I2C or SHIFTIN might work.
Here is a little about both for working with an EEPROM, maybe it will get you started?
http://www.picbasic.co.uk/forum/content.php?r=165-Serial-EEPROM-Part-1

iw2fvo
- 28th November 2010, 17:51
Thanks very much for the code.
I am searching now for the dew point computation in picbasic pro !

Thanks a lot for the help

Ambrogio
IW2FVO



A quick google search got me to here for some basic stamp code. It may help. You could also search sht75 on this site for some more hits.

http://www.emesystems.com/OL2sht1x.htm

Please don't double post. I moved your post to this thread, even though it is pretty much the same as the first post.




'{$STAMP BS2}
' SHT15.bs2 version C
' (c) 2002, 2004 Tracy Allen, http://www.emesystems.com
' access the Sensirion model sht11 or sht15
' humidity and temperature chip
' temperature to xx.x degrees Celsius, RH to xx.x %
' Repeatedly shows raw data and converted values on debug screen.
' version B, corrects glaring error in humidity computation
' also adjusts timeout to allow use with faster stamps too.
' version C updates the math for temperature compensation of %RH
' and enables display of negative temperatures
' hookup sht11 or sht15 as follows for this program
'
' STAMP SENSIRION
' 220
' p1 ----o-----/\/\---o--pin 3 sck, clock
' |
' ;---/\/\-----' pull-down
' | 4.7k
' Vss--o-o---------------pin 1 common
' |
' === 0.1uf
' |
' Vdd--o-o---------------pin 4 +5 volts
' | 4.7k
' '---/\/\-----; pull-up
' |
' 220 |
' p0 ----------/\/\---o--pin 2 dta, data
'
'
' The following code does not implement the CRC checking


sck PIN 1
dta PIN 0 ' note, 5k-10k pull-up, also 330ohm between the dta on stamp to dta on sht
dtain var in0

shtTR CON 3 ' read temperature
shtRH CON 5 ' read humidity
shtSW CON 6 ' status register write
shtSR CON 7 ' status register read
shtS0 CON 30 ' restore status register defaults (be sure to delay 11 milliseconds)

cmd VAR Byte
result VAR Word ' raw result from sht, also used as counter
r0 VAR result.byte0
r1 VAR result.byte1
degC VAR Word ' degrees Celsius * 100
RH VAR Word ' %RH * 10
RHtc VAR Word ' for temperature compensation of RH

initialize:
outs=0
dirs=%1111111111111101
GOSUB shtrst ' reset communication with sht

DO
getTemperature:
cmd=shtTR ' temperature command to sht
GOSUB shtget16
degC=result+5/10-400 ' from 100ths to 10ths of a degree with rounding
DEBUG tab,REP "-"\degC.bit15,DEC ABS degC/10,".",DEC1 ABS degC
getHumidity:
cmd=shtRH ' humidity command to sht
GOSUB shtget16
RH=(26542-(54722**result+result))**result-40
' temperature compensation follows:
RHtc=655+(result*5)+(result**15917) ' intermediate factor
RHtc=(RHtc**(degC+2480))-(RHtc**2730)+RH ' compensated value
DEBUG tab, DEC result,tab,"%RH=",DEC RH/10,".",DEC1 RH
DEBUG tab,"%RHtc=",DEC RHtc/10,".",DEC1 RHtc,cr
PAUSE 1000
LOOP

' initializes communication with sht
shtRst:
SHIFTOUT dta,sck,lsbfirst,[$ffff\16]
RETURN

' get 16 bits of data, enter with command in "cmd"
shtget16:
gosub shtcmd ' send the command "cmd"
gosub shtwait ' wait for command to finish
shiftin dta,sck,msbpre,[r1] ' msbyte
low dta ' acknowledge
pulsout sck,10
input dta
shiftin dta,sck,msbpre,[r0] ' lsbyte
input dta ' terminate communication
pulsout sck,10
return

' send start sequence and command
shtcmd:
shtStart: ' send the start sequence
' dta: ~~~~~|_____|~~~~~~
' sck: ___|~~~|_|~~~~|____
' while dta is low, clock goes low and then high
input dta ' pullup high
high sck
low dta
low sck
high sck
input dta
low sck
shtcmd1: ' send the command
shiftout dta,sck,msbfirst,[cmd]
input dta ' allow acknowledge
pulsout sck,10
return

shtWait:
' wait for sht to pull data pin low
' or for time out
result=4096
DO
result=result-1
LOOP WHILE dta & result.bit11
RETURN

</pre>

ScaleRobotics
- 28th November 2010, 18:28
Here is some code for the SHT11 for calculating dewpoint. I have not compared datasheets to know how similar (or not) they are. But this may help:

http://www.picbasic.co.uk/forum/showthread.php?t=888&p=3851#post3851

That is quite the equation! From NavMicroSystems post above:


'** Dewpoint Calculation
' See: SENSIRION Application Note "Dewpoint Calculation"
' logEW = (0.66077+7.5*T/(237.3+T)+(log(RH)-2)
' DP = ((0.66077-logEW)*237.3)/(logEW-8.16077)

DewPoint:

TempDP=Temp/10
logEW=6608
sign=TempDP.bit15
wz=ABS TempDP
wx=(7*wz)+(wz/2)
wy=2373+wz
wj=wx/wy
For ix=15 to 0 step -1
wx=(wx//wy)<<1
wz.bit0(ix)=wx/wy
Next
wx=(-sign^((wj*10000)+(wz**10000)))+sign
logEW=wx+logEW
wx=RHtc
wj=(NCD wx) - 1
wx=wx<<(15-wj)
wz=0
For ix=14 to 0 step -1
wy=wx**wx
wz.bit0(ix)=wy.bit15
bt=~wy.bit15
wx=(wy<
Next

wx=((wj*4000)**49321)+(wz**6021)
logEW=wx+logEW-30000
sign=logEW.bit15
logEW=(-sign^(((ABS logEW)+2)/4))+sign
wx=1652-logEW
sign=~wx.bit15
wx=ABS wx
wy=20402-logEW
wj=wx/wy

For ix=15 to 0 step -1
wx=(wx//wy)<<1
wz.bit0(ix)=wx/wy
Next

DP=((23730**wz)+5)/10
DP=(-sign^DP)+sign

And attached is an application note for dew point calculations.

iw2fvo
- 29th November 2010, 08:10
Hi scalerobotics,

yes, the sht_11 has the same interface characteristics of the sht_75 so the code would be OK,

Thanks for helping me,

Regards,
Ambrogio
IW2FVO


Here is some code for the SHT11 for calculating dewpoint. I have not compared datasheets to know how similar (or not) they are. But this may help:

http://www.picbasic.co.uk/forum/showthread.php?t=888&p=3851#post3851

iw2fvo
- 29th November 2010, 18:10
Good day to all in the forum.

I am using the sht15.bs2 program together with the sht_75 sensor.
I found that the temperature compensated relative humidity RHtc is not correct for temperature below 0 degC.
I think that there is a problem in the code related to the use of the degC variable;
This variable becomes negative if the temperature result is less than 4000 ( this is equivalent to 0degC ): in the RHtc computation this negative value could generate problem...

I will appreciate very much any help or comment .
Thanks
Ambrogio
Iw2fvo

Dave
- 29th November 2010, 19:12
iw2fvo , I believe that would be 0% RH. (freezing) Check out this site for more info...
http://www.techtoys.com.hk/8051/AT89S52-gLCD-STK1/chp7_SHTxx_demo.pdf

Dave Purola,
N8NTA

iw2fvo
- 29th November 2010, 22:26
Hi Dave,

Thanks a lot for your reply on the matter.
I will try to better clarify the problem that I have using the SHT15.bs2 ver.C program from Tracy Allen ( emesystems).

Point _1.
The program reads the raw temperature and store it on the " result " word variable.
The temperature is obtained using the following : degC=result+5/10-400.
This means that if the result is 5000 we have +10C, if the result is 4000 temp is 0C
and if 3000 the temp is -10C. I modified the program in order to "display" the minus sign
when result is less then 4000. Result is the 14 bit raw temperature delivered by the sensor.
Up to here everythings is correct and my system shows the correct temperature. I did some comparison with the airport control tower close to my home : it is consistent.

Point _2
the program then reads the raw RH (12 bit ) and stores that value on the "result" word variable.
RH is then obtained as follows: RH=(26542-(54772**RESULT+RESULT))**RESULT-40.
At this point everything is ok to me : my PIC micro gives me the correct RH value.

Point_3
The program computes now the temperature compensated RH in two steps:
First step > RHtc=655+(RESULT*5)+(RESULT**15917)
Second Step > RHtc=(RHtc**(degC+2480))-(RHtc**2730)+RH
>>> At this point the RHtc is correct only if the temperature is above 0C or, if the raw temperature data from the sensor is more than 4000 !.
If the temperature is negative e.g. -1.7 C the RHtc is not correct. It is about 172%.
The control tower gives me T=-1.7C , rh=85% and Dew point of -3.9C.
>>> This is my problem.

I will appreciate very much if someone can give me an help to solve the troble.
May be that some other programmer ( I am not a programmer ! ) have already solved it !
Thanks in advance

Regards,
73!
Ambrogio
IW2FVO

P.s.: English is not my first language and I am not sure to have express my problem correctly: I am Italian !



iw2fvo , I believe that would be 0% RH. (freezing) Check out this site for more info...
http://www.techtoys.com.hk/8051/AT89S52-gLCD-STK1/chp7_SHTxx_demo.pdf

Dave Purola,
N8NTA

Dave
- 30th November 2010, 12:46
iw2fvo, It is not possible to have this sensor or that equation to give you acurate results below freezing. Please read this artical: http://www.rhsystems.net/papers/RH_WMO.pdf. I have used a chilled mirror in the past for this type of measurement sampling air from a test chanber at - 20 F. However the type of sensor you are using is limited as far as humidity measurements and that is why the formula is not acurate below 0C.

Dave Purola,
N8NTA

iw2fvo
- 30th November 2010, 15:57
Dave,
thanks a lot for the document you have indicated to me.
I will read it carefully.
I noted that all the weather station here on the web and the control towers broadcast RH even if the temperature is below 0C. All of them diclare a consistent RH. At this point I do not understand well. I must study a little bit more.
At the same time I am notice that my Oregon weather station gives a correct RH for negative temperature too.
The SHT15.BS2 program has a bug somewhere : I would like to know if someone solved it !
Please let me know... just in case you know a fix.
Thanks again Dave for the help.
73 !
Ambrogio
IW2FVO
North Italy



iw2fvo, It is not possible to have this sensor or that equation to give you acurate results below freezing. Please read this artical: http://www.rhsystems.net/papers/RH_WMO.pdf. I have used a chilled mirror in the past for this type of measurement sampling air from a test chanber at - 20 F. However the type of sensor you are using is limited as far as humidity measurements and that is why the formula is not acurate below 0C.

Dave Purola,
N8NTA

Dave
- 30th November 2010, 16:54
iw2fvo , I have no idea where you got the calculation you are using but the calculation is different for relative humidity ABOVE ICE.. The calculation you are using is for ABOVE WATER. Please read this artical from the people that make the sensor you are trying to use....

http://www.sensirion.com/en/pdf/product_information/Introduction_to_Relative_Humidity_E.pdf

Dave Purola,
N8NTA

iw2fvo
- 30th November 2010, 22:39
dave,
thanks for the documentation : I red this documents but I still do not undrstand the reason for which rh is normally distribuited even under 0 degC.
Please see this US weather condition in Alaska:
Anchorage, Alaska, United States

* Weather overview
* Two-week forecast
* Hour-by-hour
* Past week
* F
* C

Current Time marted 30 novembre 2010, 12.29.06 AKST
Current conditions
Sunny. Cold. -6 C
Sunny. Cold.
Change to Fahrenheit
Sunny. Cold.
Location: Merrill Field
Temperature: -6 C
Comfort level: -8 C
Dew point: -15 C
Barometer: 1005 millibars
Humidity: 48%
Visibility: 16 km
Wind: 6 km/h from 300 West-northwestDirection East-southeast
Last update: mar 11.53 AKST

They are saying -6C 48%rh and -15C dew point.

Could you please spend few more words in order for me to understand this point ?
Thanks
Regards,
Ambrogio
IW2FVO
73!




iw2fvo , I have no idea where you got the calculation you are using but the calculation is different for relative humidity ABOVE ICE.. The calculation you are using is for ABOVE WATER. Please read this artical from the people that make the sensor you are trying to use....

http://www.sensirion.com/en/pdf/product_information/Introduction_to_Relative_Humidity_E.pdf

Dave Purola,
N8NTA

Dave
- 1st December 2010, 13:13
iw2fvo, As long as the atmospheric temperature is above the dew point one, moisture will stay in a gaseous form. But there is more to it in the world of thermodynamics. First, water can be found in a gaseous, liquid or solid form. When it is still gaseous in an environment where it should be liquid, it is then called vapour, and when it is still liquid where it should be solid, it is called under-cooled. But why is that? Well, first we must differentiate between absolute humidity and relative humidity. Water molecules tend to mix with air molecules all the time; even ice evaporates as gas. This is called sublimation. Absolute humidity is the volume of water that is contained in a volume of air. The higher the temperature, the greater the volume of water it can contain. For example, at the average temperature at sea level and average pressure, of 15 C, a cubic meter of air can't contain more than 13 grams of water. When that happens, the air is saturated with moisture and the relative humidity is 100 percent. When the temperature goes down to 0 C (freezing point) the air can sustain only 5 gr/m3. The absolute humidity is then 5 gr/m3 but the relative one is still 100 percent because at saturation point, a.k.a. dew point temperature. What happens when the temperature sinks below dew point? Well, the parcel of air has to get rid of some of its moisture by condensing it into tiny water droplets. But that can only happen by giving away energy in form of heat and the tiny molecules have virtually no mass to dissipate that heat energy. They have to touch anything like a dust, smoke particle, pollen or the bonnet of your car, to condense. Likewise, it must give heat energy to go from liquid to solid and that's why you can get tiny drops of water, in the clouds, that are under-cooled all the way down to -40 C! The type of sensor you are using does not have the capability of measuring the Dew Point below 0C. therefor the calculation you are using is not valid below 0C.....

Dave Purola,
N8NTA

iw2fvo
- 1st December 2010, 13:59
Hi Dave,
I red your explanation carefully: it is very clear to me now. I did not get those points before.
I thank you very much for your help on the matter.
Bye
73!
Ambrogio
IW2FVO
North italy


iw2fvo, As long as the atmospheric temperature is above the dew point one, moisture will stay in a gaseous form. But there is more to it in the world of thermodynamics. First, water can be found in a gaseous, liquid or solid form. When it is still gaseous in an environment where it should be liquid, it is then called vapour, and when it is still liquid where it should be solid, it is called under-cooled. But why is that? Well, first we must differentiate between absolute humidity and relative humidity. Water molecules tend to mix with air molecules all the time; even ice evaporates as gas. This is called sublimation. Absolute humidity is the volume of water that is contained in a volume of air. The higher the temperature, the greater the volume of water it can contain. For example, at the average temperature at sea level and average pressure, of 15 C, a cubic meter of air can't contain more than 13 grams of water. When that happens, the air is saturated with moisture and the relative humidity is 100 percent. When the temperature goes down to 0 C (freezing point) the air can sustain only 5 gr/m3. The absolute humidity is then 5 gr/m3 but the relative one is still 100 percent because at saturation point, a.k.a. dew point temperature. What happens when the temperature sinks below dew point? Well, the parcel of air has to get rid of some of its moisture by condensing it into tiny water droplets. But that can only happen by giving away energy in form of heat and the tiny molecules have virtually no mass to dissipate that heat energy. They have to touch anything like a dust, smoke particle, pollen or the bonnet of your car, to condense. Likewise, it must give heat energy to go from liquid to solid and that's why you can get tiny drops of water, in the clouds, that are under-cooled all the way down to -40 C! The type of sensor you are using does not have the capability of measuring the Dew Point below 0C. therefor the calculation you are using is not valid below 0C.....

Dave Purola,
N8NTA

Dave
- 2nd December 2010, 00:59
Ambrogio, Thats OK, as I am no expert myself... I personally don't bother with the humidity information here in Michigan when the temp's are below freezing.. Only the wind chill factor... There is a lot of information on Dew Points and Humidity on the web. I only hope I was able to help out... 73's for now...

Dave Purola,
N8NTA


Hi Dave,
I red your explanation carefully: it is very clear to me now. I did not get those points before.
I thank you very much for your help on the matter.
Bye
73!
Ambrogio
IW2FVO
North italy

iw2fvo
- 6th December 2010, 18:31
Another item for the RH sensor...
This is the explanation provided by the sensor manufacturer ( Sensirion ):

Quote:

Thank you for your e-mail. The SHT75 can measure RH below 0C. However as cold air below 0C contains only a small amount of water molecules it is very difficult to measure them accurately. Therefore tolerances increase.

Hope this answers your question.

Best regards

Reto Kleiner
_____________________________________

Reto Kleiner
Technical Customer Support

SENSIRION the sensor company
Laubisruetistrasse 50
CH-8712 Staefa ZH
Switzerland

phone: +41 44 306 40 00
direct: +41 44 927 11 44
fax: +41 44 306 40 30
mailto:reto.kleiner@sensirion.com
www.sensirion.com

Von: Ambro_IW2FVO [mailto:iw2fvo@yahoo.com]
Gesendet: Samstag, 4. Dezember 2010 15:27
An: Info
Betreff: sht_75

unquote .




QUOTE=Dave;96720]Ambrogio, Thats OK, as I am no expert myself... I personally don't bother with the humidity information here in Michigan when the temp's are below freezing.. Only the wind chill factor... There is a lot of information on Dew Points and Humidity on the web. I only hope I was able to help out... 73's for now...

Dave Purola,
N8NTA[/QUOTE]

iw2fvo
- 19th December 2010, 17:43
Hi to all in the forum !

Is there any additional comment on this subject ?

Thanks

Ambrogio
IW2FVO



Another item for the RH sensor...
This is the explanation provided by the sensor manufacturer ( Sensirion ):

Quote:

Thank you for your e-mail. The SHT75 can measure RH below 0C. However as cold air below 0C contains only a small amount of water molecules it is very difficult to measure them accurately. Therefore tolerances increase.

Hope this answers your question.

Best regards

Reto Kleiner
_____________________________________

Reto Kleiner
Technical Customer Support

SENSIRION the sensor company
Laubisruetistrasse 50
CH-8712 Staefa ZH
Switzerland

phone: +41 44 306 40 00
direct: +41 44 927 11 44
fax: +41 44 306 40 30
mailto:reto.kleiner@sensirion.com
www.sensirion.com

Von: Ambro_IW2FVO [mailto:iw2fvo@yahoo.com]
Gesendet: Samstag, 4. Dezember 2010 15:27
An: Info
Betreff: sht_75

unquote .




QUOTE=Dave;96720]Ambrogio, Thats OK, as I am no expert myself... I personally don't bother with the humidity information here in Michigan when the temp's are below freezing.. Only the wind chill factor... There is a lot of information on Dew Points and Humidity on the web. I only hope I was able to help out... 73's for now...

Dave Purola,
N8NTA[/QUOTE]