Sensirion SHT11 with a PIC16F628-20


View Poll Results: Have I included enough relevant material to make the problem clear?

Voters
1. You may not vote on this poll
  • YES. I see what you mean

    0 0%
  • COULD BE BETTER: Kind of understand what your trying to say

    1 100.00%
  • NO: What the heck are you talking about

    0 0%
Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    4


    Did you find this post helpful? Yes | No

    Default 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
    Last edited by psenek; - 26th January 2011 at 11:47.

  2. #2
    Join Date
    Apr 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Talking 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 ....

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default 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
    Charles Linquist

  4. #4
    Join Date
    Apr 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default 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
    Last edited by yohanfx; - 11th April 2011 at 03:54.

  5. #5
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default 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 View Post
    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

Similar Threads

  1. Watchdog Timers
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 19:03
  2. INT2 anomaly in DT_INTS-18??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2010, 21:07
  3. capture/repeat data ?
    By Sam in forum Serial
    Replies: 44
    Last Post: - 27th November 2006, 04:19
  4. A little DTMF help
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 48
    Last Post: - 30th May 2006, 02:31
  5. Serout PIC16F628 to PC R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2005, 01:29

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts