Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic: SHT11 help — Parallax Forums

PropBasic: SHT11 help

skynuggetskynugget Posts: 172
edited 2010-09-19 18:14 in Propeller 1
hey all, im trying to come up with a driver for the SHT11 Temp/Humidity sensor, and im coming up a little short.

the following code is producing unexpected results, and im not sure if its my math or my read and write routines. is anyone familiar enough with this sensor able to steer me in the right direction?
SUB SHT_GetTmp
	RawT		var		__param1
	tmp		var		__param2
	
	SHT_Start					' start sequence
	SHT_WRByte SHT_Tmp			' request temperature
	SHT_WAIT					' wait up to 250ms to measure	
	
	RawT = SHT_RdByte Ack		' get first byte
	tmp =  SHT_RdByte NoAck		' get second byte
	
	tx_dec rawt 'debug msb
	tx_byte 13	'debug cr
	tx_dec tmp	'debug lsb
	tx_byte 13	'debug cr
	
	RawT = RawT << 8			' shift over first byte
	RawT = RawT | tmp			' combine the low byte
	RawT = RawT << 16			' shift over for a 16bit result
	\ SAR RawT,#16				' shift the sign as well
	
	tx_dec rawt 'debug raw temp
	tx_byte 13	'debug cr
	
	'sensiron forumula: celcius = RawT * .01 - 40
	TempC = RawT ** 42949673                 'rawt * .01
	TempC = TempC - 40				'-40
	
	tx_dec tempC	'debug celcius
	tx_byte 1		'debug home
	
	
ENDSUB

thanks so much in advance!

Comments

  • Christof Eb.Christof Eb. Posts: 1,247
    edited 2010-09-19 02:13
    Hi, Skynugget,
    this is not much information about your problem.
    To find out the source of problems - data connection or maths, I would try to display raw data first. If this reacts to temperature changements, then I would try to debug maths.
    Good luck,
    Christof
  • skynuggetskynugget Posts: 172
    edited 2010-09-19 12:00
    Ha! i got it figured out i think. i just made a simple change to the variable declarations at the top of the SHT_GetTmp
    SUB SHT_GetTmp
    	RawT		var			long '__param1
    	tmp		var			long '__param2
    

    instead of aliasing a param, i declared long. though i thought you could alias a param for use to save space?

    EDIT: i think param got reset in a nested sub call

    thanks for looking everyone! ill post the rest when i get er all done.
  • skynuggetskynugget Posts: 172
    edited 2010-09-19 18:14
    so i have a working program for retrieving Celsius, Fahrenheit, and humidity. however while adding more features, i got a compiler error, "exceeds FIT" which im assuming means that i ran out of program space.

    so i opted to use the LMM code, but now im getting a compiler error "Address out of range".

    ive attached what im working with, uncomment the lmm at program start to see what i mean. am i overlooking something else?

    thanks again!
Sign In or Register to comment.