SHT_75 with picbasic pro


Results 1 to 20 of 20

Threaded View

  1. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    '{$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>
    Last edited by ScaleRobotics; - 28th November 2010 at 15:02.
    http://www.scalerobotics.com

Members who have read this thread : 0

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