Sensirion SHT85
in BASIC Stamp
Has anyone successfully set up I2C comms to this humidity sensor from a Basic Stamp?
The sensor sends data pairs (16 bit temp,16 bit humidity).
Thanks!
Comments
My book, StampWorks, shows how to do essential I2C with a BASIC Stamp. Memory is limited, though, so there are no guarantees you'll have enough in a generic BS2 for the task you have.
Download code and PDF here: https://www.parallax.com/package/stampworks-experiment-kit-manual-and-code/
The attached code is for the SHT31, SHT85, SHT30 and SHT35, part numbers vary by physical package, accuracy, and temperature range.
Note how the ** multiplier simplifies conversion of the raw 16 bit values into Celsius and %RH.
The code here is for Stamps in the p series (2p, 2pe and 2px) that support the native I2CIN and I2COUT commands. With the earlier Stamps (2, 2sx, 2e) you'd need to patch in JonnyMac's code that implements the i2c methods in PBASIC. Could be condensed a bit to target the SHT85 specifically, if you run short of memory.
'''
'{$STAMP BS2pe}
'{$PBASIC 2.5}
' Tracy Allen, EME Systems
' BASIC Stamp 2pe demo code for the SHT31, SHT30, SHT35 & SHT85
' This will work on any Stamp in the p series that support the i2c command.
' need pullups on both scl and sda
rawT VAR WORD
rawH VAR WORD
tC VAR WORD
rH VAR WORD
check VAR WORD ' checksum, acquired but not used.
i2cpin CON 0 ' p0 for sda, p1 for scl...alternative on 40-pin stamps is p8 for sda, scl is p9.
sht31id CON $88 ' 8-bit device ID, $44 is the 7-bit ID. Alternative, $90,$45
main:
DEBUG CR,"Hello SHT3x",CR
DO
PAUSE 1000
I2COUT i2cpin, sht31id,[$24,$0B] ' request temperature and RH, medium resolution&speed
PAUSE 10 ' conversion takes up to 6ms at medium repeatability, no clock hold
I2CIN i2cpin, sht31id, [rawT.BYTE1, rawT.BYTE0,check,rawH.BYTE1,rawH.BYTE0,check]
tC = rawT ** 17500 - 4500
rH = rawH ** 1000 ' xx.x
DEBUG CR,"rawT= ",DEC rawT," degC= ",DEC tC/100,".",DEC2 tC
DEBUG " rawH= ",DEC rawH," %RH= ",DEC rH/10,".",DEC1 rH
LOOP
'''
Hello Tracy, Jon, from Lagoa, Portugal!
Thanks for the help.
I will try this code and let you know how it goes.....
Mark W