Shop OBEX P1 Docs P2 Docs Learn Events
HST11 sensor code — Parallax Forums

HST11 sensor code

bob kruggelbob kruggel Posts: 50
edited 2009-07-28 21:20 in Accessories
I am going through the Basic Stamp code (page 6 of 8) and have either found an error or I don't understand the ** operator. I've copied some comment lines and one line of code below. I added the line numbers.


1.' linearize humidity
2.' rhLin = (soRH * 0.0405) - (soRH^2 * 0.0000028) - 4
3.' for the BASIC Stamp:
4.' rhLin = (soRH * 0.0405) - (soRH * 0.002 * soRH * 0.0014) - 4
5.' Conversion factors are multiplied by 10 to return tenths

6.'rhLin = (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40

Line 2 is from the SHT11 spec sheet and describes how to adjust the non-linearity of the humidity sensor.

Line 4 rewrites the second half of the formula to assure that the calculation of (soRH^2*.0000028) stays within the limits of BASIC math.

Line 6 makes use of the ** operator to multiple by a fraction and also·multiplies the formula in 6 by 10 to get an answer in tenths.

Line 6 should read in decimal 6. rhLin=(soRH**.405)-(10*(soRH**.002*soRH**.0014))-400.

This can be written as (soRH**.405)-(soRH**.02**soRH**.0014)-400 or (soRH**.405)-(soRH**.002**soRH**.014)-400

Converting the fractions to hex·as described in the help screen·(soRH**$67AE) -(soRH**$51e*soRH**$5B)-400.

The use of ** is very confusing, but I think this is correct.

Bob Kruggel

Comments

  • Tracy AllenTracy Allen Posts: 6,656
    edited 2009-07-28 04:45
    Hi Bob,

    I do think you're correct about the error in the SHT11 code. Your version with $51E correctly includes the factor of 10, whereas the version with $83 in the documentation does not.

    It makes a substantial difference, especially at high %RH, as shown in the attached table. The version with $83 substantially overestimates the %RH and can come up with values >100%RH. The column "RH error" is the difference between using $15E and $83.

    I looked back at my own code at here and see that I did the computation in a different order. That result is in the table in column "EME"--whew! seems to be correct. I do agree the use of ** can be confusing.

    attachment.php?attachmentid=62529

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 7/28/2009 5:37:22 AM GMT
    562 x 119 - 14K
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2009-07-28 18:28
    I also had a lot of confusion about the ** operator when I first started learning to interact with the SHT11 sensors. It took a while to wade through it and I did make a few scribbles during the confusion.

    I am working on a web page for my SHT11 sensor modules I sell and I am hoping to include some of my notes that I took while figuring things out. Maybe they will help others. (probably not as much as Tracy Allen's site though)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • bob kruggelbob kruggel Posts: 50
    edited 2009-07-28 21:20
    Tracy,

    Thanks for the conformation. Some times when I'm learning new stuff I doubt myself too much.

    BobK
Sign In or Register to comment.