Sht4x


+ Reply to Thread
Results 1 to 3 of 3

Thread: Sht4x

  1. #1
    Join Date
    Sep 2009
    Posts
    741

    Default Sht4x

    Does anyone have SHT40 example code?
    I'm trying for 2 days, and no progress. Is it posible with i2cwrite, i2cread command?
    Trying to do conversion and read data, all 0's. Trying to read serial no, al 0's.
    HW connection looks good.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,397


    Did you find this post helpful? Yes | No

    Default Re: Sht4x

    what have you tried ?
    i fumbled around a bit with a scd41 which has a similar modus operandi and managed to get it to work with i2cread/write commands eventually , trick was to send a dummy 0 write prior to the needed delay before the result was read back
    Warning I'm not a teacher

  3. #3
    Join Date
    Sep 2009
    Posts
    741


    Did you find this post helpful? Yes | No

    Default Re: Sht4x

    Got it working, stupid datasheet....
    Address is $88, not $44, as in datasheet.
    Found that using
    https://www.picbasic.co.uk/forum/sho...C-Ping-program
    Then is straight forward
    1. Read serial
    Code:
    SHTAdr=$88
    SHTCmd=$89
    I2CREAD S_SDA1,S_SCL1,SHTAdr,SHTCmd,[SHTArray[0],SHTArray[1],SHTArray[2],SHTArray[3],SHTArray[4],SHTArray[5]]
    0-1 serial 1 word, 2 crc, 3-4 serial 2 word, 5 crc
    2.Start conversion
    Code:
    SHTAdr=$88
    SHTCmd=$FD
    I2CWRITE S_SDA1,S_SCL1,SHTAdr,SHTCmd,SensorFailNoAck
    3. Read Temp and RH data after 20mS
    Code:
    SHTAdr=$88
    I2CREAD S_SDA1,S_SCL1,SHTAdr,[SHTArray[0],SHTArray[1],SHTArray[2],SHTArray[3],SHTArray[4],SHTArray[5]]
    0-1 hold temp, 2 hold crc, 3-4 hold humidity, 5 hold crc.
    If I add SensorFailNoAck, then it trigers every time, not sure why... I'll use crc to check for correct communication.
    CRC8 routine:
    Code:
    CalcCRC:
    crc=$ff
     for byteCtr = 0 to 1
        TmpB=CRCArray[byteCtr]
        crc  = crc ^ TmpB
        for  i = 0 to 7
            if crc.7=1 then
                crc = (crc << 1)
                crc =  crc ^ $31
            else
                crc =crc << 1
            endif
        next i
     next byteCtr
    Need to check calculation from ticks to T[C] and RH[%].
    And to try to understand heater... How and why to use it.
    Last edited by pedja089; - 6th June 2024 at 20:52.

Members who have read this thread : 12

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