Sensirion Temp/Humidity - 28x2 - stumped!

shoei600

New Member
Dear forum,
I have made good use of some code in the finished section from 'dorfusf' (many thanks for posting), and it works fine with a Sensirion SHT75 sensor connected to pins c.1 and c.2 for clock and data. I have now spent many hours trying to get a second sensor working without success only to find (after taking everything back to basics) that this sensor will only work on c.1 and c.2. If I move the c.2 to c.0 to free up c.2 and c.3 for the new sensor I seem to get bad bytes coming back.

What cold be the difference in these pins function to stop this code from working? I'm not using any of the specific pin functions.

Many thanks in advance, this is a superb forum and full credit to all the regular contibutors. I read with interest everyday.

Code:
hsersetup B38400_8, %00
setfreq m8
'====================Constants==================
Symbol TempMeas       		= %00000011	 	'Measure Temp command
Symbol HumMeas        		= %00000101		'Measure Humidity command
Symbol StatRegWrite   		= %00000110 	'Write to Status Register command
Symbol StatRegRead    		= %00000111 	'Read from Status Register command
'Symbol Setup 	    		= %00000001		'Status Register write, set precision'
'=====================inputs==================='
Symbol Sensin 	= pinC.0 'pinc.2 works fine
'====================Outputs===================
Symbol Sensout 	= C.1  'c.1 is correct for data
Symbol Sensclock 	= C.0  'c.2 works fine
'====================Varaibles==================
Symbol DataLow 	= b0	'Working Byte Low 1
Symbol DataHigh 	= b1	'Working Byte High 1
Symbol DataWord 	= w0	'Working Word 1 = b0 & b1
Symbol DataLow2 	= b2 	'Working Byte Low 2
Symbol DataHigh2 	= b3 	'Working Byte High 2
Symbol DataWord2 	= w1	'Working Word 2 = b2 & b3
Symbol counter 	= b5	'counter
'====================Temp and Hum variables===================
Symbol RH2 		= W19
Symbol soRH 	= W20
Symbol RH1 		= W21
Symbol RHlin 	= W22
Symbol Hum 		= W23
Symbol HighHum 	= b44
Symbol LowHum 	= b45
Symbol TempW 	= W26
Symbol Temp 	= W27
'----------------------

'===============================================================
'=======================Initilizing devices=====================
'===============================================================
Main:
hserout 0, ("starting",13,10)	'Write Humidity to dispaly
pause 5000
hserout 0, ("started",13,10)	'Write Humidity to dispaly'
			
Repeat: 
'	debug
	gosub Tempread				' READ THE TEMP 
	gosub Humread				' READ THE HUMIDITY
	gosub TempHumdisplay			' DISPLAY THE TEMP & HUM'
'	hserout 0,("loop",13,10)
goto repeat

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'##########################################SHT 1 SUBROUTINES##################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TempHumDisplay:
		DataWord = Temp					
		if Temp >= 40 then SkipNeg1			'Check negative
		pause 10
		DataWord = 40 - Temp 				'Change because negative
'----------------------------Convert into ASCII for display-------------------------
SkipNeg1: 
		DataHigh2 = DataWord / 100 + $30
		DataLow2 = DataWord // 100
		DataHigh = Datalow2 // 10 + $30
		Datalow2 = Datalow2 / 10 + $30
		pause 10  
		hserout 0, ("BathroomTemp=+",DataHigh2,DataLow2,".",DataHigh,"C",13,10)	'Write Temperature to LCD
'====================Binary to ascii conversion and then disp on lcd========
		Dataword = RHlin
		DataHigh2 = DataWord / 100 + $30
		DataLow2 = DataWord // 100
		DataHigh = Datalow2 // 10 + $30
		Datalow2 = Datalow2 / 10 + $30
		pause 10  
		hserout 0, ("BathroomHumd=",DataHigh2,DataLow2,".",datahigh,"%",13,10)	'Write Humidity to dispaly
	return
'============================Temperature measurement==============
TempRead: 	
		Datalow = TempMeas			'Load measuring command
		gosub shtstart				'Initiate transmission
		gosub writedata				'Write CMD to sensor
		gosub acklow
		pause 500					'Pause 
		Dataword = 0	
		gosub readdata				'Read first byte
		gosub acklow
		Dataword = Dataword * 256		'Shift first MSB byte to MSB pos in Word
		gosub readdata				'Read lsb in LSBpos in word
		gosub ackhigh
		Dataword = Dataword / 10 - 400	'divide by 10 as 
		Temp = Dataword
	return	
'=========================Measuring the Humidity===================
HumRead: 
	DataLow = HumMeas
	gosub shtstart 						'Transmission start sequences				 'Load humidity measure instruction
	gosub WriteData						'Write instruction
	gosub Acklow						'Provide low acknowledge
	pause 500							'Wait for Measurement
	RHlin = 0
	DataWord = 0						'Clear variable for measurement
	gosub readData 						'Read first byte, empty
	gosub acklow						'Provide low acknowledge
	Dataword = Dataword * 256				'Shift first MSB byte to MSB pos in Word
	gosub ReadData 						'Read second byte
	gosub Ackhigh						'Provide high acknowledge
									'The next formulas are from Nuts&Volts 91 from parallax.
		soRH = dataword					'SHT datasheet formula RH=(soRH*0.0405)-(soRH2*0.0000028)-4
		RH2 = soRH ** 26542				'Formula for basic:
		RH1 = soRH ** 3468				'RHlin = (soRH ** 26542)
		RHlin = RH1 * RH1 + 50 / 100			'RHlin = rhlin - ((sorh**3468)*(sorh**3468) + 50 /100)
		RHlin	= RH2 - RHlin
		RHlin = RHlin - 40 
		return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TransStart ' 'Sensor Transmission Start Sequence, used to begin
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SHTstart:
	low sensclock					 'START sequence
	high sensout
	high sensclock
	low sensout
	low sensclock
	high sensclock
	high sensout
	low sensclock
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WriteData ' 'Write Data byte in DataLow to Sensor '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WriteData: 
		shiftout sensclock, sensout, 1, (Datalow/8)	' shiftout commands
	return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' AckHigh  ''High Acknowledge to Sensor
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Ackhigh: 
	high sensout 				'Output High
	pulsout sensclock,10			 'Pulse clk
return
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' AckLow ' 'Low Acknowledge to Sensor '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Acklow:   
	 low sensout				' output low
	pulsout sensclock,10			' pulse clk
return
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ReadData 'Read Byte from Sensor into DataLow
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ReadData: 						'shift_in routine 
	input sensout				'Change pin to input to recievedata
	for Counter = 1 to 8			'count to 8 for 8 bits	 
	Datalow = Datalow * 2			'move bit 1 pos up
	if sensin = 0 then skipMSBpre		'if bit 0 skip
	Datalow = Datalow + 1			'if bit 1 add to byte
skipMSBpre: 
	pulsout sensclock,1 			'puls the clock for 1 ms
	next Counter
	output sensout				'change pin to output for acknowledge.
return
 

hippy

Ex-Staff (retired)
What cold be the difference in these pins function to stop this code from working? I'm not using any of the specific pin functions.
The only hardware difference seems to be that C.0 and C.1 aren't ADC pins but C.2 and C.3 are. I cannot see any obvious reason why that should matter here. All C.x are Schmitt Trigger inputs.

Perhaps, rather than moving both pins to others simultaneously, try moving one at a time, seeing which causes problems.
 

shoei600

New Member
I had tried moving the clock to b.0 and then b.1 thinking that pwm capable pins might work work also the same bad results.
I've tried both sensors on c0 to c3 but in pairs so c.0 & c.1 for sensor 1 and c.2 & c.3 for sensor 2, which if the adc is key then I need c.2 & c.3 for the clock cycles for each sensor instead.
Hippy, you're a star.
Thank you, I'll try it tomorrow.
 
Last edited:

shoei600

New Member
View attachment Air Handlling Manager SHT75 - developing version 4.bas

Hi Hippy,
Well another dabble tonight and the new pins showed promise then i realised that the 'pinC.0' should have been the same as the data leg not the clock hence 'pinC.1' instead. I have had this correct for both sensors in the past so I then went ahead and tried the second sensor on the other pins. This didnt work initially but did work every 6th cycle so it was clear that there was some timing that was out.
On another very close inspection I then found that where I have renamed all the variables with '_2' on the end to duplicate the sensor routines I had missed 'if sensin_2 = 0 then skipMSBpre_2' his line almost at the end so for when certain readings were returned the second sensor routine would jump back in to the first sensor routine.
Problem solved.
I'll post the full code here (so far). Its a brain for a heat recovery ventilation system in the house. Having closed every hole to draught-proof the home I noticed that the humidity was creeping up. This allows me to control the tickover and boost function and monitor H and T outside and in the bathroom and also two Dallas Temp sensors for air out to the house and the ambient to check the recovery unit is actually recovering heat from the stale air intake.
Many thanks for your help once again.
Kind regards.
 

yv1hx

Member
Hi shoei600,

I have some thing unclear from this post, how you connected the SHT-xx sensor to the Picaxe 28x2 ?? the original code from Charles Andrew (http://eprints.usq.edu.au/2406/) and PHanderson (S.K.) suggest the use of a resistor between the picaxe pins used for data input and output.

Best regards,
 

shoei600

New Member
I'm running everything at 3.3v then just the 10k resistor between +V and data (i think, from memory) as per the sensirion data sheet. Both clock and data pins then connect directly to picaxe. Any picaxe pins should do.
 

yv1hx

Member
Hi shoei600,

I'm suspecting having the same problem related by you in the #1 post, I'm using a Picaxe 28x2 (running at 5v) and I'm always getting garbage in the first digit and the other figures doesn't change with the temperature or humidity (I borrowed a hairdryer from my wife ;)

I'm planning get a lots of patience and do some trial and error testings changing the pins between the SHT-15 and the Picaxe ...
 
Top