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


    Did you find this post helpful? Yes | No

    Unhappy sht11 vs. 16f84A

    I'm using the above code with a 16f84a and getting a consistent number, which is clearly wrong. I'm getting humvalue 16003 and tempval 4000. And since I haven't burst into flames this seems unlikely to be accurate.

    I also tried using a modified Keunyoung Oh's code for the 16f877 (found http://itp.nyu.edu/physcomp/sensors/Code/SHT11 ) but received similar results (consistent & wildly inaccurate numbers), though with different numbers.

    Any idea why this might be?

    Also, as a possible explanation: I'm using the DIP sht11 which has a 117 on the sensor. I'm assuming I should use the pin diagram which goes with sensirion sht11 sensor module #28018, but all the other pin diagrams are different.

    any suggestions would be helpful.

    thanks,
    Adam

  2. #2


    Did you find this post helpful? Yes | No

    Post sht11 v 16f84a follow up

    here's the full code I'm currently (trying to use) everything compiles and publishes in PBP, but still no good data. is my code messed up?
    Code:
    '*******************************[ SHT11 Sample Code ]********************************
    ' File...... SHT11.bas
    ' Purpose... SHT11 digital humidity sensor sample code
    ' MCU....... Microchip PIC16F877
    ' Software.. Converted to Proton+ 2.0 from PBPro ver 2.4
    ' Author.... Brandon Tarr
    ' E-Mail.... [email protected]
    ' Web....... http://www.spectrumedix.com
    ' Started... May 15, 2002
    ' Updated...
    ' Version... 1.0
    '************************************************* *************************
    
    'device 16f884a
    
    DEFINE xtal 4
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1
    
    TEMP con 1
    HUMI con 2
    ' adr command r/w
    Symbol statusregw = $06 ' 000 0011 0
    Symbol statusregr = $07 ' 000 0011 1
    Symbol measuretemp = $03 ' 000 0001 1
    Symbol measurehumi = $05 ' 000 0010 1
    Symbol resett = $1e ' 000 1111 0
    
    ' -----[ Variables ]---------------------------------------------------------------------
    ledPin             var     PORTB.0
    ledVar var byte
    
    rxPin              var     PORTB.3
    txPin              var     PORTB.2
    SCK var PORTA.4 ' SHT11 SCK
    SDATA var PORTB.1 ' SHT11 DATA
    
    i  var byte
    f var byte
    value var byte
    errorr var bit
    mode var byte
    ack var bit
    
    vall var byte
    pktvalue var word
    pktchksum var byte
    
    humival var word
    tempval var word
    dewpoint var byte
    checksum var byte
    
    ' -----[ Initialization ]----------------------------------------------------------------
    'ADCON1 = 7 ' Set PORTA and PORTE to digital
    'Low PORTE.2 ' LCD R/W line low (W)
    Pause 500 ' Wait for LCD to start
    'lcdout $fe, 1
    
    ' -----[ Main Code ]---------------------------------------------------------------------
    usetheSHT11:
        SerOut2 txPin, 16468, [" ", 10, 13]
        High ledPin          ' Turn on LED connected to PORTB.0
        Pause 500       ' Delay for .5 seconds
        Low ledPin           ' Turn off LED connected to PORTB.0
    
        gosub connectionreset
        value = measurehumi
        gosub measure ' measure humidity
        humival = pktvalue * 1000
        humival = DIV32 4095
        'lcdout $fe, 2, " ", $fe, 2, "Humidity: ", dec humival / 10, ".", dec humival // 10, "%"
        value = measuretemp
        gosub measure ' measure temperature
        tempval = pktvalue * 1000
        tempval = DIV32 16383
        'lcdout $fe, $c0, " ", $fe, $c0, "Temperature: ", dec tempval / 10, ".", dec tempval // 10, 223, "C"
        SerOut2 txPin, 16468, ["humival  ", DEC humival, 10, 13]
        SerOut2 txPin, 16468, ["tempval  ", DEC tempval, 10, 13]
    
        pause 500 '100 decrease sample time
    goto usetheSHT11
    
    ' -----[ Subroutines ]-------------------------------------------------------------------
    connectionreset:
    ' communication reset: DATA line is high and at least 9 SCK cycles followed by transstart
    ' ________________________________________ _____
    ' SDATA: |_____|
    ' _ _ _ _ _ _ _ _ _ __ __
    ' SCK: _| |_| |_| |_| |_| |_| |_| |_| |_| |___| |__| |___
        input SDATA
        high SDATA
        low SCK ' set initial state
        for i = 1 to 9 ' 9 SCK cycles
        high SCK
        low SCK
        next
        gosub transstart ' transmission start
    return
    
    transstart:
    ' generates a transmission start
    ' ___ _____
    ' SDATA: |_____|
    ' __ __
    ' SCK: __| |__| |___
    
        high SDATA
        low SCK ' set initial state
        high SCK
        low SDATA
        low SCK
        high SCK
        high SDATA
        low SCK
    return
    
    measure:
    ' makes a measurement (humidity/temperature) with checksum
        errorr = 0
        gosub transstart ' transmission start
        gosub writebyte
        for i = 1 to 255 ' wait until sensor has finished the measurement
            if SDATA = 0 then
                goto meascomplete
        endif
        pause 1
        next
    meascomplete:
        if SDATA != 0 then ' or timeout (~2 sec.) is reached
            errorr = 1
        endif
        ack = 1
        gosub readbyte ' read the first byte (MSB)
        pktvalue.highbyte = vall
        gosub readbyte ' read the second byte (LSB)
        pktvalue.lowbyte = vall
        ack = 0
        gosub readbyte ' read checksum (no acknowledge to put sensor in "sleep" mode)
        pktchksum = vall
    return
    
    writebyte:
        ' writes a byte on the Sensibus and checks the acknowledge
        errorr = 0
        i = $80
        while i > 0
            if (i & value) != 0 then ' masking value with i
                high SDATA ' write to SENSI-BUS
            else
                low SDATA
            endif
            high SCK ' clk for SENSI-BUS
            low SCK
            i = i / 2 ' shift bit for masking
        wend
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
        high SCK ' clk #9 for ack
        errorr = SDATA ' check ack (SDATA will be pulled down by SHTXX)
        low SCK
    return
    
    readbyte:
    ' reads a byte from the Sensibus and gives an acknowledge in case of "ack=1"
        vall = 0
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
        i = $80
        while i > 0
            high SCK ' clk for SENSI-BUS
            if SDATA = 1 then ' read bit
                vall = vall | i
            endif
            low SCK
            i = i / 2
        wend
        TRISB.1 = 0 ' grab SDATA-line
        SDATA = ack ' in case of "ack", pull down DATA-Line
        high SCK ' clk #9 for ack
        low SCK
        high SDATA
        TRISB.1 = 1 ' release SDATA-line
    return
    
    softreset:
    ' resets the sensor by a softreset
        errorr = 0
        GOSUB connectionreset ' reset communication
        value = resett
        gosub writebyte ' send RESET-command to sensor
    return
    Last edited by ScaleRobotics; - 6th April 2011 at 15:23. Reason: added code brackets for code tags

  3. #3
    Join Date
    Jan 2008
    Location
    Dublin, Ireland
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Hmmmm. This was a valid interesting topic.... pity it ends in the middle of nowhere without a solution!

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tonyfelloni View Post
    Hmmmm. This was a valid interesting topic.... pity it ends in the middle of nowhere without a solution!
    I think there are a couple of other working examples somewhere here on the forums.
    And heck, if the original poster doesn't care if the problem is solved, why should anyone else?

  5. #5
    Join Date
    Jan 2008
    Location
    Dublin, Ireland
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Hey Skimask

    I care because its relevant to something I am working on now.... To find the perfect thread....only to discover you have been led up the garden path, haha. Not to worry, I did see a few other relevant posts elsewhere.

    Cheers
    Tony

  6. #6
    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 10:47.

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

  8. #8
    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, 18:03
  2. INT2 anomaly in DT_INTS-18??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2010, 20:07
  3. capture/repeat data ?
    By Sam in forum Serial
    Replies: 44
    Last Post: - 27th November 2006, 03:19
  4. A little DTMF help
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 48
    Last Post: - 30th May 2006, 01:31
  5. Serout PIC16F628 to PC R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2005, 00:29

Members who have read this thread : 1

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