Sensirion SHT11 with a PIC16F628-20
	
	
		Greetings-
  I 've recently moved from the BS2 to the PIC Basic Compiler Pro software.
  I'm trying to attach a Sensirion SHT11 Temperature and Humidity sensor to the Pic 16F628-20 and then send the Calculated values in Celcius and Farenheit, as well as Relative Humidity %RH  to the COM1 port on my windows machine.
  I have found many sample source code, but none seem to work for me when I compile.  Either written for a separate compiler, or a different chip, so the   #Include   statements are wrong.
Can anyone help me along here?  I would really appreciate it.
If any other information is required, please let me know.
Thank you,
Christian
EPIC PROGRAMMER
PIC BASIC COMPILER PRO
16F628-20    
20-MHz External Xtal
	 
	
	
	
		Missing part of code SHT11
	
	
		For anyone trying to get this first off, add wx=wy<< bt+(bt & wx.bit15)
instead of the truncated part Christian had indicated.
(nice work on the code Ralph)
This works fine on a PIC16F876A 20mhz using portc.3 and portc.4
I can see why Ralph had problems with it not posting properly. I had to
put in a space before the first  bt  to see it properly as without the space
it was truncating my reply too. Anyone else have a problem posting code
like this?
(helps to look at the preview)
Hope this helps someone.
Ron
	 
	
	
	
		Sometimes I feel tired ... but why ????
	
	
	
	
	
		addition to NavMicroSystems example
	
	
		Hi!
I know this is an old thread but this might still help someone.
NavMicroSystems' example works fine, if you place wx=wy<< bt+(bt & wx.bit15)
instead of wx=(wy< Next.
It has some issues with negative temperatures but ok...
It's important that you don't forget 10k pullup on DTA line.
There's one more thing: you should replace all HIGH dta
commands with INPUT dta.
Datahseet SHT1x @ page 5.
"To avoid signall contention the microcontroller must only
drive DATA low".
When you have appropriate (10k) pullup on dta the line
goes high if you set the dta pin to input. I tested it and
it works perfectly fine.
Also: if this is your first attempt to communicate with SHT1x maybe
you should consider omitting dewpoint calculations and just read
raw data.
For room ambient (i had about 22°C and 35 %RH when testing) you should
get readings like 0x1855 for 14bit temperature and 0x03EE for 12bit humidity).
Best regards, 
Rok
	 
	
	
	
		Hepl me please............
	
	
		I want to program SHT11, with language PBP or Pbasic
want to know the temperature and humidity with SHT11.
please help me ....
	 
	
	
	
		Re: Sensirion SHT11 with a PIC16F628-20
	
	
		I have successfully used the code below with an 18F2321.
It should work the same with a 16F part.
I found it somewhere here on the forum, and it works great.
	Code:
	
'------------------ Read SHT71 Temperature / Humidity Sensor -------------------
        
ReadSHT71:
    SHTCommand = ReadTemp
    gosub Initialize
    GOSUB TransmissionStart
    GOSUB IssueCMD
    gosub ConvertToCelsius
    
    
    SHTCommand = ReadHumidity
    gosub Initialize
    GOSUB TransmissionStart
    GOSUB IssueCmd
    gosub ConvertToRH
    TEMPC = (TempC/100) - 2 
    TempC.7 = SignC      
    RHTempComp = RHTempComp/100
    RETURN
   
    
'--------------------- Calculate Relative Humidity -----------------------------
ConvertToRH:
' 12 Bit    RHLinear = -4 + 0.0405 * DataOutput -0.0000028 * DataOutput^2
    w = 405 * RawData
    w = div32 100
    x = RawData * RawData
    x = div32 1000
    x = x * 28
    x = div32 100
    RHLinear = w - x - 400
'---------- Calculate Relative Humidity with Temperature Compensation ----------
    w = (8 * RawData + 1000) / 10
      IF SignC = 0 THEN      ' "+"  
        if tempC > 2500 then
            x = (tempC - 2500) * w
            x = div32 100
            RHTempComp = RHLinear + x / 100
            else
            x = (2500 - tempc) * w
            x = div32 100
            RHTempComp = RHLinear - x / 100
        endif
        else
        x = (2500 + tempC) * w
        x = div32 10000
        RHTempComp = RHLinear - x
    endif
    return
'---------------------------- Initialize the Sensor ----------------------------
Initialize:
    high DataPin                   ; Start condition
    low clk
    for i = 1 to 10
        high clk
        pause 1
        low clk
        pause 1
    next i                          ; Leaves clock low
    return
'---------------------------- Get Data from Sensor -----------------------------
IssueCmd:
    Pause 2
    low Clk
    shiftout DataPin,clk,1,[SHTCommand\8]       ' Send command byte
    input DataPin                                                            
WaitForAck:
     x = 0
WaitForAck2:
    IF DataPin = 1 THEN
      x = x + 1
      if x = 0 then goto NoAck
      Pauseus 2
      GotoWaitForAck2
    ENDIF  
      
    High Clk
    pause 10                                    ' Issue ACK from PIC
    low clk
    
    pause 10                                    ' Make certain we don't move forward on a glitch
    WHILE DataPin:WEND
                                     
   
    shiftin DataPin,clk,0,[RawData.byte1\8]     ' Get the first byte, 8 bits
    low DataPin
    
    HIGH Clk
    PAUSE 10
    LOW Clk
    pulsout clk,10                              ' Send NACK
    shiftin DataPin,clk,0,[RawData.byte0\8]     ' Get the second byte, 8 bits
    low DataPin
    pulsout clk,10                              ' Send acknowledge
    shiftin DataPin,clk,0,[crc\8]               ' Get third byte, 8 bits, CRC
    high DataPin
    pulsout clk,10                              ' Send acknowledge
    input DataPin                               ' End of Transmission
    input clk
    ERR = 0
    return
NoAck:
    ERR = 1
    RETURN
'---------------------------- Start Transfer -----------------------------------
TransmissionStart:
    HIGH DataPin      ; Make sure it is high
    Pause 1
    high clk
    pause 1
    low DataPin
    pause 1
    low clk
    pause 1
    high clk
    pause 1
    high DataPin
    pause 1
    low clk
    return
'----------------------------- Raw Data to Degrees C ---------------------------
ConvertToCelsius:
' 14 Bit    Temperature = -40.00 + 0.01 * DataOutout
    if RawData => 4000 then
        tempC = RawData - 4000
        SignC = 0
               
        else
        tempC = 4000 - RawData         ; Negative Temps
        SignC = 1
    endif
    return
 
	 
	
	
	
		Re: Sensirion SHT11 with a PIC16F628-20
	
	
		what software you use as a compiler?
pardon my beginner programing and
program how to display the sensor readings of temperature and humidity SHT11 to 16bit and two-line LCD ....
thanks very much
	 
	
	
	
		Re: addition to NavMicroSystems example
	
	
		Hi ,
I am going to implemant the dew point computation with this sensor and with a PIC baděsic Pro.
I agree that there is an errot in DP calculation when the temperature is under 0°C.
Any help to solve the problem? Or any updated code ?
Thanks for helping.
Regards,
Ambrogio
	Quote:
	
		
		
			
				Originally Posted by 
psenek
				 
			Hi!
I know this is an old thread but this might still help someone.
NavMicroSystems' example works fine, if you place wx=wy<< bt+(bt & wx.bit15)
instead of wx=(wy< Next.
It has some issues with negative temperatures but ok...
It's important that you don't forget 10k pullup on DTA line.
There's one more thing: you should replace all HIGH dta
commands with INPUT dta.
Datahseet SHT1x @ page 5.
"To avoid signall contention the microcontroller must only
drive DATA low".
When you have appropriate (10k) pullup on dta the line
goes high if you set the dta pin to input. I tested it and
it works perfectly fine.
Also: if this is your first attempt to communicate with SHT1x maybe
you should consider omitting dewpoint calculations and just read
raw data.
For room ambient (i had about 22°C and 35 %RH when testing) you should
get readings like 0x1855 for 14bit temperature and 0x03EE for 12bit humidity).
Best regards, 
Rok