Shop OBEX P1 Docs P2 Docs Learn Events
Sensirion / Prop Proto eratic temp / humidity readings fluctuating — Parallax Forums

Sensirion / Prop Proto eratic temp / humidity readings fluctuating

TinkerGeekTinkerGeek Posts: 7
edited 2011-02-26 23:06 in Accessories
Hi,

I'm trying to run my first tests on the Sensirion SHT11 temp/humidity sensor on my Propeller Proto USB board. When I run the SensirionDemoFull.spin object, and I view the the results in the ParallaxSerialTerminal, I get three lines of incorrect readings followed by one correct. This behavior repeats. As you can see below, I keep my office nice and toasty at 73 deg F and the humidity is around 28% so I think these are right, but where is the -11.2 degrees and -.8% humidity coming from?

MSG,Sensirion SHT-11 Demo
Temp_raw, RH_raw, TC_float, TF_float, RH_float, DewPtC_float, DewPtF_float, TF_fixpt, RH_fixpt, status_byte
CLEARDATA
DATA, 6282, 853, 23.1, 73.6, 28.0%, 3.6, 38.4, 73, 27, 00000000,
DATA, 6288, 852, 23.2, 73.7, 27.9%, 3.6, 38.5, 73, 27, 00000000,
DATA, 1572, 54,-24.0,-11.2, -0.8%, 0.0, 0.0, 73, 28, 00000011,
DATA, 1572, 54,-24.0,-11.2, -0.8%, 0.0, 0.0, 73, 28, 00000011,
DATA, 1572, 54,-24.0,-11.2, -0.8%, 0.0, 0.0, 73, 28, 00000011,
DATA, 6289, 853, 23.2, 73.7, 28.0%, 3.6, 38.5, 73, 27, 00000000,
DATA, 1573, 54,-24.0,-11.1, -0.8%, 0.0, 0.0, 73, 27, 00000011,
DATA, 1572, 53,-24.0,-11.2, -0.8%, 0.0, 0.0, 73, 28, 00000011,
DATA, 1572, 54,-24.0,-11.2, -0.8%, 0.0, 0.0, 73, 28, 00000011,
DATA, 6292, 852, 23.2, 73.8, 27.9%, 3.6, 38.6, 73, 27, 00000000,

Thanks for any help.

-Roger

Comments

  • Mark KiblerMark Kibler Posts: 546
    edited 2011-02-22 17:02
    Roger,

    While I won't be much help technically I would suggest that you post your program code for others to digest and decipher. We used the same sensor on a BOE with a Basic stamp and other friends on the forum were really helpful.

    I suspect that since you're getting a valid reading every fourth line the problem may simply be in the program code and not a wiring problem. Otherwise you wouldn't get any good reading at all. The fact that there's a repeating pattern in your readings supports my suspicions.

    I really don't write program code all that well but I'm pretty sure that if you post your code, someone will help you figure it out. Good luck and please keep us all posted.

    Regards,

    Mark
    ARLISS Team New Hampshire
    :cool:
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2011-02-22 21:47
    Interesting, I never saw the Sensirion_ Full Demo object until I tried searching for it from your post. Anyhow, from looking through the code, my assumption (without actually running it) is that you have some timing issues that are causing the readings to be corrupted. If you look at lines 80-85, there is an IF routine that is making some configuration changes to the SHT11. However, line 85 is commented out which is a pause. It's possible that the Repeat at line 42 is cycling too quick for the Sensirion without the pause at line 85. Try uncommenting line 85 or comment out lines 80-84. Have you tried the regular Sensirion Demo?
  • TinkerGeekTinkerGeek Posts: 7
    edited 2011-02-24 09:55
    Mark,

    I am using the code from the object exchange without modifications. It can be found here: http://obex.parallax.com/objects/637/

    Thanks,

    Roger
    Roger,

    While I won't be much help technically I would suggest that you post your program code for others to digest and decipher. We used the same sensor on a BOE with a Basic stamp and other friends on the forum were really helpful.

    I suspect that since you're getting a valid reading every fourth line the problem may simply be in the program code and not a wiring problem. Otherwise you wouldn't get any good reading at all. The fact that there's a repeating pattern in your readings supports my suspicions.

    I really don't write program code all that well but I'm pretty sure that if you post your code, someone will help you figure it out. Good luck and please keep us all posted.

    Regards,

    Mark
    ARLISS Team New Hampshire
    :cool:
  • TinkerGeekTinkerGeek Posts: 7
    edited 2011-02-24 10:16
    Andrew,

    Thanks for the reply. I work as a .net developer but am VERY green when it comes to micro controllers. I'm still trying to learn spin. I tried un-commenting line 85 but I'm still getting the bad values.

    I did find a workaround though. I noticed that the last term in the output is the Status Byte. All of the bad lines has a status of 00000011 .... and all the good lines ends in 00000000. So I made an if statement so that I can grab good values only. I forgot to mention that my goal is to output the temp and humidity to an LCD. So my if loop only sends good values to LCD when it sees status of 00000000. See the code below. (If there is a better way to structure this PLEASE let me know)

    Thanks,

    Roger

    PUB main | count,tmp,rawTemp, rawHumidity, tempC, rh, dewC, TF_fp, RH_fp

    LCD.Init( E, RS, RW, DBHigh, DBLow )
    LCD.usDelay( 5_000_000 ) ' time enough to switch to PST

    serial.start(31, 30, 0, 9600) 'start(rxpin, txpin, mode, baudrate)
    serial.rxFlush

    'term.start(31, 30, 0, 115200)
    f.start ' start floating point object
    sht.start(SHT_DATA, SHT_CLOCK) ' start sensirion object

    waitcnt(clkfreq*3+cnt)
    sht.config(33,sht#off,sht#yes,sht#hires) 'configure SHT-11
    'term.tx(CLS)

    ' read SHT-11 sensor and update (note: need to set baud to 57K if want output data to PLX-DAQ)
    LCD.RawSetPos( $00 ) ' "first" line
    LCD.PrintStr(String("Sensirion SHT-11",10,13))
    LCD.usDelay( 2_000_000 )

    repeat
    'term.Str(String("DATA,"))
    rawTemp := f.FFloat(sht.readTemperature)
    rawHumidity := f.FFloat(sht.readHumidity)

    tempC := celsius(rawTemp)
    'term.str(fp.FloatToFormat(fahrenheit(tempC), 5, 1))
    'term.str(string("F,"))

    rh := humidity(tempC, rawHumidity)
    'term.str(fp.FloatToFormat(rh, 5, 1))
    'term.str(string("%, "))

    dewC := dewpoint(tempC, rh)
    TF_fp:=sht.getTemperatureF
    RH_fp:=sht.getHumidity
    status:=sht.readStatus
    'term.str(string(13))

    if sht.readStatus==00000000
    LCD.CLEAR
    LCD.RawSetPos( $00 ) ' "first" line
    LCD.PrintStr( string("TEMP:"))
    LCD.PrintStr(fp.FloatToFormat(fahrenheit(tempC), 5, 1))
    LCD.PrintStr( string("F") )

    LCD.RawSetPos( $40 ) ' "second" line
    LCD.PrintStr( string("REL HUM:") )
    LCD.PrintStr(fp.FloatToFormat(rh, 5, 1))
    LCD.PrintStr(string("%"))
    LCD.usDelay( 2_000_000 )

    if count//4 'toggle every 4 cycles
    sht.config(33,sht#off,sht#no,sht#lores) '3 fast, loRes measurements
    else
    sht.config(33,sht#off,sht#yes,sht#hires) '1 slow, hiRes measurement
    count++
    ' waitcnt (clkfreq*2+cnt) 'display every 2 seconds
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2011-02-24 11:25
    I had not been aware of that object either. The author only gives his handle, "BR", but I found a thread where he talked about his effort and Andrew had pitched in there too.
    http://forums.parallax.com/showthread.php?123805-Sensirion-SHT-11-driver-and-reference-circuit

    I haven't looked closely, but it appears that you have adopted the demo ("SensirionDemo_full"), not just the object ("Sensirion_full").

    In the demo, you will find this code, which is what makes it print out 4 records, 3 ostensibly at low resolution and 1 at high resolution. I suggest you jettison the three and keep the one.
    if count//4                                       'toggle every 4 cycles
           sht.config(33,sht#off,sht#no,sht#lores)         '3 fast, loRes measurements
         else
           sht.config(33,sht#off,sht#yes,sht#hires)        '1 slow, hiRes measurement
         count++
    
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2011-02-24 11:38
    Glad you got it working and I think I can tell you why your code works. After another quick peek at the Sensirion SHT11 Datasheet (right side of the SHT11 page), it is clear that it is a timing issue. Getting 00000011 back from the status register means that the device is still reading the temperature. The odd thing is that the Sensirion_full.spin file does appear to have proper code to grab the condition (ack) of the data line (which gets pulled low when the SHT11 is done measuring), but I do not see any code that waits for the ack to be low. (it just reads it). Since using 14 bit temperature reading can take up to 320ms, I think that is where the timing bug is coming into play and if you get 00000011 back as a status byte, the device is still reading and your results are corrupt. From the datasheet, section 3.3:

    After issuing a measurement command (‘00000101’ for
    relative humidity, ‘00000011’ for temperature) the
    controller has to wait for the measurement to complete.
    This takes a maximum of 20/80/320 ms for a 8/12/14bit
    measurement. The time varies with the speed of the
    internal oscillator and can be lower by up to 30%. To
    signal the completion of a measurement, the SHT1x pulls
    data line low and enters Idle Mode. The controller must
    wait for this Data Ready signal before restarting SCK to
    readout the data. Measurement data is stored until
    readout, therefore the controller can continue with other
    tasks and readout at its convenience.


    So, if your status byte is 00000000 then the device is idle and you are able to get a valid reading.
  • TinkerGeekTinkerGeek Posts: 7
    edited 2011-02-25 18:51
    Tracy,

    Now this is a stupid question... but I would like to post an improved code snipet but I can't figure out how to put it in a "code" window like you did.

    Can you tell me or point me to the doc that explains it?

    Thanks!

    Roger
  • FranklinFranklin Posts: 4,747
    edited 2011-02-26 08:30
    If you go to the advanced option in your post you get more options.
    code here
    
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2011-02-26 10:08
    There are a couple of ways to put the code in a box. There should be a row of formatting options across the top of your relpy window, and one of those options should be a "#" symbol. If not, you may need to find and click on a button "advanced" at the bottom right corner of your reply window. Select the text that you want to be inside the box and then click on the "#" icon. Another way to do it is to add [ code][ /code] tags yourself before and after the text. Like this, but do not put the space after the opening [

    [ CODE]sht.config(33,sht#off,sht#yes,sht#hires) '1 slow, hiRes measurement[ /CODE]

    The system interprets this as a formatting command and displays it like this:
    sht.config(33,sht#off,sht#yes,sht#hires)        '1 slow, hiRes measurement
    
  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2011-02-26 13:45
    Good search work Tracy! I was wondering where that came from and who BR was. Didn't remember that I answered questions for him way back then.....
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2011-02-26 23:06
    Just for kicks, have you tried some of the other code in the OBEX for this sensor? The one that you posted doesn't seem to have many downloads... that's ok, there is nothing wrong with that. Every piece of published code has to start somewhere, but since the number of downloads are low for the particular reference you are using, it might not have had an appropriate amount of time to mature itself away from any unforeseen bugs in the software.

    Here is a version from the OBEX with almost 2000 downloads that may or may not provide more desirable results.

    http://obex.parallax.com/objects/21/


    As a secondary note, always double check your wiring, and make sure that the components are seated properly and have adequate connections.
Sign In or Register to comment.