Shop OBEX P1 Docs P2 Docs Learn Events
Sensirion SHT11 Sensor — Parallax Forums

Sensirion SHT11 Sensor

wafa86wafa86 Posts: 44
edited 2010-12-09 18:27 in Accessories
hi...

I have Sensirion SHT11 Sensor module and it has been interfaced with BS2PX module. the only problem that when the program try to read from the sensor the value is alwayes fix and not logical whether for Temperature or Humidity data. The readen data is alwayes = $FFFF it is so wierd. I used the following code that is in that link:

http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/SensirionDocs.pdf

and I attach the result also. So what to do to fix this problem????
1280 x 800 - 165K

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-11-27 17:12
    If you would attach your code and the pins you have the sensor connected to it will help. Also, is the sht11 the one from parallax?
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2010-11-27 23:06
    That particular set of readings is what you get if the clock and data lines are swapped or not connected. Check your physical connections to the code, the data line should be connected to P1 and the clock line should be connected to P0.
  • wafa86wafa86 Posts: 44
    edited 2010-11-28 06:15
    I changed the data and clock pins.

    ShtData PIN 6 'data pin in the Sensirion SHT11 Sensor Module to read the values
    ShtClock PIN 7 'Clock pin in the Sensirion SHT11 Sensor Module to generate the CLK from BS2PX Microcontroller
    RX PIN 2 ' Receive Pin
    TX PIN 0 ' Transmit Pin

    and the pin 0 is reserved to the easy bluetooth module is it effect my result if I change the pin numbers????:confused:
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-11-28 16:04
    The SHT11 requires a pullup resistor on its data line. A pulldown resistor is recommended (but not required most of the time, depending on power supply sequence) on the clock line. The Parallax module 28108 includes the pullup resistor. Are you using the Parallax module?

    Another potential pitfall is that the Parallax module, (item code 28018) has different pin connections than the Sensirion chip. People sometimes read the wrong document for the pin connections.
    Parallax 28018: ground:4 Vdd:8 Data:1 Clock:3
    Sensirion SHT11: ground:1 Vdd:4 Data:2 Clock:3
  • wafa86wafa86 Posts: 44
    edited 2010-11-29 07:19
    I have Parallax module 28108 which is exist in the following link:

    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/28018/List/0/SortField/4/ProductID/94/Default.aspx

    and I connected the exact connection of the module that you explained. The connection is:
    Parallax 28018: ground:4 Vdd:8 Data:1 Clock:3

    data pin (pin1) in the module I connected it to pin 6 in Board of Education, and clock pin (pin3) in the module I connected it to pin 7 in Board of Education. So, is the module interfacing with BS board valid?? I cannot do any simulation to the module manually or by using software to check out the voltage level!!! what to do to fix this problem???
  • FranklinFranklin Posts: 4,747
    edited 2010-11-29 09:29
    It would help if you would attach your entire program so we could look for errors.
  • wafa86wafa86 Posts: 44
    edited 2010-11-29 09:38
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    ' =========================================================================
    '
    ' I/O Definitions
    '
    ShtData PIN 6 ' bi-directional data
    Clock PIN 7
    RX PIN 2 ' Receive Pin
    TX PIN 0 ' Transmit Pin
    '
    ' Constants
    '
    ShtTemp CON %00011 ' read temperature
    ShtHumi CON %00101 ' read humidity
    ShtStatW CON %00110 ' status register write
    ShtStatR CON %00111 ' status register read
    ShtReset CON %11110 ' soft reset
    Ack CON 0
    NoAck CON 1
    No CON 0
    Yes CON 1
    Baud CON 396 '9600 Baud Rate

    '
    ' Variables
    '

    ioByte VAR Byte ' data from/to SHT11
    ackBit VAR Bit ' ack/nak from/to SHT11
    toDelay VAR Byte ' timeout delay timer
    timeOut VAR Bit ' timeout status
    soT VAR Word ' temp counts from SHT11
    tC VAR Word ' temp - Celcius
    tF VAR Word ' temp - Fahrenheit
    soRH VAR Word ' humidity counts
    rhLin VAR Word ' humidity; linearized
    rhTrue VAR Word ' humidity; compensated
    status VAR Byte ' status byte
    '
    ' EEPROM Data
    '
    '
    ' Initialization
    '
    Initialize:
    GOSUB SHT_Connection_Reset ' reset device connection
    PAUSE 250 ' let DEBUG window open
    '
    ' Program Code
    '
    Main:
    DO
    GOSUB Measure_Temperature
    SEROUT TX,Baud,[ DEC soT, CR]
    SEROUT TX,Baud,[ DEC (tC / 10), ".", DEC1 tC, CR, CR]

    GOSUB Measure_Humidity
    SEROUT TX,Baud,[ DEC soRH, CR]
    SEROUT TX,Baud,[ DEC (rhLin / 10), ".", DEC1 rhLin, "%", CR, DEC (rhTrue / 10), ".", DEC1 rhTrue, "%"]
    PAUSE 1000
    LOOP
    '
    ' Subroutines
    '
    ' connection reset: 9 clock cyles with ShtData high, then start sequence
    '
    SHT_Connection_Reset:
    SHIFTOUT ShtData, Clock, LSBFIRST, [$FFF\9]
    ' generates SHT11 "start" sequence
    ' _____ _____
    ' ShtData |_______|
    ' ___ ___
    ' Clock ___| |___| |___
    '
    SHT_Start:
    INPUT ShtData ' let pull-up take high
    LOW Clock
    HIGH Clock
    LOW ShtData
    LOW Clock
    HIGH Clock
    INPUT ShtData
    LOW Clock
    RETURN
    ' measure temperature
    ' -- celcius = raw * 0.01 - 40
    ' -- fahrenheit = raw * 0.018 - 40
    '
    SHT_Measure_Temp:
    GOSUB SHT_Start ' alert device
    ioByte = ShtTemp ' temperature command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait for measurement
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soT.HIGHBYTE = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    soT.LOWBYTE = ioByte
    ' Note: Conversion factors are multiplied by 10 to return the
    ' temperature values in tenths of degrees
    tC = soT ** $1999 - 400 ' convert to tenths C
    tF = soT ** $2E14 - 400 ' convert to tenths F
    RETURN
    ' measure humidity
    '
    SHT_Measure_Humidity:
    GOSUB SHT_Start ' alert device
    ioByte = ShtHumi ' humidity command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait for measurement
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soRH.HIGHBYTE = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    soRH.LOWBYTE = ioByte
    ' linearize humidity
    ' rhLin = (soRH * 0.0405) - (soRH^2 * 0.0000028) - 4
    '
    ' for the BASIC Stamp:
    ' rhLin = (soRH * 0.0405) - (soRH * 0.002 * soRH * 0.0014) - 4
    '
    ' Conversion factors are multiplied by 10 to return tenths
    '
    rhLin = (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40
    ' temperature compensated humidity
    ' rhTrue = (tc - 25) * (soRH * 0.00008 + 0.01) + rhLin
    '
    ' Conversion factors are multiplied by 10 to return tenths
    ' -- simplified
    '
    rhTrue = (tC - 250) * (soRH ** $34) + rhLin
    RETURN
    'sends "status"

    SHT_Write_Status:
    GOSUB SHT_Start ' alert device
    ioByte = ShtStatW ' write to status reg cmd
    GOSUB SHT_Write_Byte ' send command
    ioByte = status
    GOSUB SHT_Write_Byte
    RETURN
    'returns "status"

    SHT_Read_Status:
    GOSUB SHT_Start ' alert device
    ioByte = ShtStatW ' write to status reg cmd
    GOSUB SHT_Read_Byte ' send command
    ackBit = NoAck ' only one byte to read
    GOSUB SHT_Read_Byte
    RETURN
    ' sends "ioByte"
    ' returns "ackBit"
    '
    SHT_Write_Byte:
    SHIFTOUT ShtData, Clock, MSBFIRST, [ioByte] ' send byte
    SHIFTIN ShtData, Clock, LSBPRE, [ackBit\1] ' get ack bit
    RETURN
    ' returns "ioByte"
    ' sends "ackBit"
    '
    SHT_Read_Byte:
    SHIFTIN ShtData, Clock, MSBPRE, [ioByte] ' get byte
    SHIFTOUT ShtData, Clock, LSBFIRST, [ackBit\1] ' send ack bit
    INPUT ShtData ' release data line
    RETURN
    ' wait for device to finish measurement (pulls data line low)
    ' -- timeout after ~1/4 second
    '
    SHT_Wait:
    INPUT ShtData ' data line is input
    timeOut = No ' assume no timeout
    FOR toDelay = 1 TO 250 ' wait ~1/4 second
    IF (ShtData = 0) THEN EXIT
    PAUSE 1
    NEXT
    IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
    RETURN

    ' reset SHT11/15 with soft reset
    '
    SHT_Soft_Reset:
    GOSUB SHT_Connection_Reset ' reset the connection
    ioByte = ShtReset ' reset command
    ackBit = NoAck ' only one byte to send
    GOSUB SHT_Write_Byte ' send it
    PAUSE 11 ' wait at least 11 ms
    RETURN
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-11-29 10:12
    It may be timing out too soon due to the speed of the 'px. Try this modified routine:
    SHT_Wait:
       INPUT ShtData ' data line is input
       timeOut = No ' assume no timeout
       FOR toDelay = 1 TO 250 ' needs time to finish
         IF (ShtData = 0) THEN EXIT
         PAUSE 2     ' <--------------------increased the wait time
       NEXT
       IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
       RETURN
    
  • wafa86wafa86 Posts: 44
    edited 2010-11-29 11:00
    I tried to pause 2 ms to 10 ms and it did not work, it still gives the same result that I attached. can I increase delay or I do some thing else in the code???
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-11-29 12:20
    Try a DEBUG in that same routine:
    IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
    DEBUG CR,?toDelay
       RETURN
    

    Report back what it says about the value of toDelay. If I get a chance later on today, I'll try it for go or no go with a 'px.
  • wafa86wafa86 Posts: 44
    edited 2010-11-29 12:34
    the values of todelay = 251???

    I have attached the result.


    what to do next???
    1280 x 800 - 112K
    R1.jpg 112.3K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-11-29 22:34
    Hi wafa86,
    I loaded the code you posted above into a BS2px and (after a few unrelated changes) it ran just fine, displaying the correct temperature and humidity. I'm guessing there is a bad connection in your hardware, somewhere, or something is wrong with the sensor or the stamp. The first thing I would do is check the power supply on the sensor and the presence of signals on pins p6 and p7.

    The changes I made were only in the main loop, to send the values to the DEBUG screen instead of to bluetooth:
    Main:
       DO
       GOSUB SHT_Measure_Temperature  ' <--- was typo in subroutine name
       DEBUG DEC soT, TAB   '<------------DEBUGs instead of SEROUT, TAB instead of CR
       DEBUG DEC (tC / 10), ".", DEC1 tC, TAB,TAB
    
       GOSUB SHT_Measure_Humidity   ' <--- was typo in subroutine name
       DEBUG DEC soRH, TAB
       DEBUG DEC (rhLin / 10), ".", DEC1 rhLin, "%", TAB, DEC (rhTrue / 10), ".", DEC1 rhTrue, "%",CR
    PAUSE 1000
    LOOP
    
  • wafa86wafa86 Posts: 44
    edited 2010-12-01 10:22
    do I have to use the heater bit to operate the module, and what the usage of the heater bit???

    see my code:

    IF ReceivedChar = "h" THEN 'heater on
    SEROUT TX,Baud,[ " Heater is ON", CR]
    status = %00000100
    GOSUB SHT_Write_Status


    ELSEIF ReceivedChar = "f" THEN 'heater off
    SEROUT TX,Baud,[ " Heater is OFF", CR]
    status = %00000000
    GOSUB SHT_Write_Status

    and if I have to use it, I have to set the heater bit befor reading the tempereture and humidity sensors?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-12-01 11:28
    No need to turn on the heater. That has nothing to do with the communications.

    Try the status register:
    ShtStatR CON %00111 ' status read
    That is a test of communications apart from the sensing function. If you turn on and off the heater, that fact should show up in the status register.
    main:
      DO
        GOSUB SHT_read_status
        DEBUG CR, BIN8 ioByte    ' should display 00000000
        status = %00000101      ' turn on heater, select low res
        GOSUB SHT_Write_Status
        GOSUB SHT_read_status
        DEBUG TAB, BIN8 ioByte   ' should display 00000101
        status = %00000000         ' default high res, heater off
        GOSUB SHT_Write_Status
        PAUSE 1000
      LOOP
    
  • wafa86wafa86 Posts: 44
    edited 2010-12-05 08:44
    Hi

    I still have the problem of the reading values in the SHT11, I ll attach my circuit. I have another question, how to compile from .bpx file to .hex file using the BS editor????
  • wafa86wafa86 Posts: 44
    edited 2010-12-05 08:49
    SHT11.jpg
    tha attachment:
    530 x 440 - 21K
  • wafa86wafa86 Posts: 44
    edited 2010-12-06 07:19
    Hi Tracy...

    about the test that you have done, did you used ths same pins that I used in my code, which are:

    pin 6 ---> data pin
    pin 7 ---> clock pin

    Because in the code for the SHT11 , the data pin ---> pin 1 and clock pin ---> pin 0, is my problem related to the pins assignment? and I have checked the voltage in the hardware, In Pin 8 on SHT11 is connected to VDD and I have checked the voltage on that pin by using the Ameter, which was 5V and Pin 4 was connected to VSS = 0V, the data and clock pins are connected perfectlly to the BS2PX. I don't think there is a problem in the connection, also I exclude that there is any problem in the BS2PX, because I connected the BS2PX to other sensors and they worked perfectlly with reading the logical values.

    I already attached the hardware connection circuit, but can you take a look to this new circuit, should I use this connection instead????

    circuit1.JPG


    I have Proteus simulator v7.6, and it has all modules of BS2 except the BS2PX that I have !!!, can I use one of the modules instead of BS2PX module??? and which module is the closest one to BS2PX??? I will make the circuit in the simulator interfacing one of the modules with SHT11 to see If there is any software problem. In addition, I need to know how to convert the .bpx file to .hex file?? can the BS editor implement such a thing???????

    I hope you answered my questions as soon as possible....

    thanks alot:smile:
    500 x 320 - 15K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2010-12-06 09:40
    You told us you have the Parallax module 28018, so the first circuit is the one to use. If you had the raw Sensirion chip (surface mount) or a non-Parallax modules that brings the pins straight out, only then would you contemplate the second circuit.

    I cut and pasted your program as you posted it above, except for the changes that I noted. I used pins p6 and p7, and the Sensirion RH and temp data came through as expected.

    Have you tried the Parallax distribution example code directly, with the sensor attached to p0=clk, p1=dta? If you have another SHT11 module or another Stamp, it would be good to swap them in. Certainly, try the Proteus simulation with a different Stamp.

    I'm not sure what you mean by a HEX file. What do you want to do? You can use the option on the "Generate object file" on the File menu to make a HEX object file.
  • wafa86wafa86 Posts: 44
    edited 2010-12-06 14:15
    I need the .hex file to download it on the Proteus simulator circuit of SHT11 interfacing it with the BS microcontroller. I cannot use the .bpx file I need to convert the .bpx file to another file with the extinsion of .hex file.that the microcontroller can deal with??? and for simulation, what is the BS module u recommend it to be used for simulation which has the almost same functions, job and speed as the BS2PX ??????
  • wafa86wafa86 Posts: 44
    edited 2010-12-08 05:03
    ????????????????????????????????????????????????????
  • FranklinFranklin Posts: 4,747
    edited 2010-12-08 15:24
    ?????????????????????????????????????????????????? ??
    What is that supposed to mean?
  • wafa86wafa86 Posts: 44
    edited 2010-12-09 05:52
    Franklin, do have an answer for my Question I mean Questions ?????????????????!!!!!!!!!!!!!!!!!!!!!!!
  • FranklinFranklin Posts: 4,747
    edited 2010-12-09 18:27
    Seems to me the questions you've asked have been answered. Your just not following up on them.
Sign In or Register to comment.