Sensirion SHT11 Sensor
wafa86
Posts: 44
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????
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????
Comments
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????
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
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???
' {$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
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.
I have attached the result.
what to do next???
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:
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?
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.
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????
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????
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
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.