Code for SHT21


Closed Thread
Results 1 to 5 of 5

Thread: Code for SHT21

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Location
    Ohio, USA
    Posts
    57


    Did you find this post helpful? Yes | No

    Default Re: Code for SHT21

    mpgmike, I got the sensor to respond to my finger temp difference. Here is the code so far:

    Yes, yes, I am prototyping on a Stamp :/

    Code:
    ' {$STAMP BS2p}
    ' {$PBASIC 2.0}
    
      tf    VAR Byte
      tc    VAR Byte
      rawT  VAR Word
      rawRH VAR Byte
    
      PAUSE 250                                     ' let DEBUG window open
      DEBUG CLS
      DEBUG "SHT21 Demo", CR
      DEBUG "----------", CR
    
    Main:
    
    I2COUT 0 ,%10000000, [%11100011]
      PAUSE 50
    I2CIN  1 , %10000001, [rawT]
      DEBUG 2, 0, 3
      DEBUG "rawT...... "
      DEBUG  DEC rawT, 11, CR
      rawT= rawT <<2
      tC = (rawT & $fffc) ** 17572 - 4685
      DEBUG "Deg C......", DEC tC
      PAUSE 500
    
    
      GOTO main
    Getting elevated readings on the SHT21
    The SHT21 temp says my room is 42°C (107.6°F) Actual temperature is ~ 23.8°C (75°F)
    rawT @ 42°C = 111

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


    Did you find this post helpful? Yes | No

    Default Re: Code for SHT21

    don't know much about stamp code but here goes

    from the sensiron web example

    //================================================== ============================
    float SHT2x_CalcTemperatureC(u16t u16sT)
    //================================================== ============================
    {
    ft temperatureC; // variable for result
    u16sT &= ~0x0003; // clear bits [1..0] (status bits)
    //-- calculate temperature [°C] --
    temperatureC= -46.85 + 175.72/65536 *(ft)u16sT; //T= -46.85 + 175.72 * ST/2^16
    return temperatureC;
    }
    the reading is not shifted <<2 places the two lsb are just masked off

    so
    rawT= rawT <<2
    becomes
    rawT= rawT & ~3 ;ie %1111111111111100


    I2COUT 0 ,%10000000, [%11100011]
    is hold master mode is that what you need ?

    try
    I2COUT 0 ,%10000000, [%11110011]

    might be better

    I2COUT 0 ,%10000000, [%11100011]
    PAUSE 50 is this long enough at max resoloution ?
    I2CIN 1 , %10000001, [rawT]

    rawT @ 42°C = 111
    by my calcs rawT should be 33132 @ 42°C

    what rawT do you actually get ?
    Warning I'm not a teacher

Similar Threads

  1. 16F877A and Sensirion SHT21
    By ctravel in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th June 2016, 08:15
  2. avr code to code for PIC
    By JasonMcG in forum General
    Replies: 1
    Last Post: - 11th September 2014, 00:57
  3. Serial problem between BasicStamp code and PBP code
    By AllanZilkowsky in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th April 2014, 02:15
  4. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44
  5. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51

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