SHT11 basic stamp code compatible with SHT21 ?
CuriousOne
Posts: 931
Hello.
I've got this module:
http://www.ebay.com/itm/SHT21-Digital-Humidity-And-Temperature-Sensor-Module-Replace-SHT11-SHT15-/200941266522?pt=LH_DefaultDomain_0&hash=item2ec908665a
I've used sample code parallax provides for SHT21 and it appears to be working - humidity readings do increase when I breath on it, or decrease when I put it to dry situation. The problem is that, I have accurite indoor humidity meter, and it's reading, which I found pretty close to real ones (according to personal feelings), are completely different. When SHT21 shows 45%, accurite shows 31% and so on.
As far as I know, that SHT21 has "true" I2C, wheile SHT11 - does not. I've tried to use both BS2 and BS2P boards - no difference.
BS2 sample code from here:
http://www.parallax.com/downloads/sensirion-temphumidity-sensor-bs2-example-code
I've got this module:
http://www.ebay.com/itm/SHT21-Digital-Humidity-And-Temperature-Sensor-Module-Replace-SHT11-SHT15-/200941266522?pt=LH_DefaultDomain_0&hash=item2ec908665a
I've used sample code parallax provides for SHT21 and it appears to be working - humidity readings do increase when I breath on it, or decrease when I put it to dry situation. The problem is that, I have accurite indoor humidity meter, and it's reading, which I found pretty close to real ones (according to personal feelings), are completely different. When SHT21 shows 45%, accurite shows 31% and so on.
As far as I know, that SHT21 has "true" I2C, wheile SHT11 - does not. I've tried to use both BS2 and BS2P boards - no difference.
BS2 sample code from here:
http://www.parallax.com/downloads/sensirion-temphumidity-sensor-bs2-example-code
Comments
If you have a 'p series Stamp, you might try the I2CIN and I2COUT commands instead of the old SHT11 protocol. I've used the SHT25 with i2c on the Propeller but haven't tried it on the Stamp.
Is there example code that works with the SHT21 ? ,
http://forums.parallax.com/discussion/157185/sht-22-and-basic-stamp/p1
(it was an sht-21, not sht-22)
The sht11 code should read the raw sensor data okay, but the math to convert to proper temperature and RH units needs to be modified. The math is easier for the sht21.
but cannot make heads or tails of it
The one thing I was never good at was the 8 bit math operations needed to significantly modify code of this magnitude. That is why I was looking for some code to work with with SHT21
Any help would be greatly appreciated on this.
This code is where I think the modifications are needed
Mike2545
The &fffc and $fff0 mask off the least significant 2 and 4 bits respectively, which the SHT21 uses to carry status information.
In Spin for the Prop I use, which could be done with ** also, but it is easier with 32 bit longs simply to multiply and then divide by 2^16 using >> 16.
similar for the humidity:
I'm betting the way to get data from the SHT21 differs....
Mike
rawT = sot << 2
rawH = soRH << 4
provided you are set for the default 14 and 12 bit resolutions respectively.
Look at pages 11–12 of the 2014 SHT2x data sheet to read the discussion of compatibility with SHT1x code.
The SHT21 temp says my room is 42°C (107.6°F) Actual temperature is ~ 23.8°C (75°F)
rawT @ 42°C = 111
Here is the code:
What do you think the calibration/ conversion issue could be?
The command %11100011 is for temperature using the clock hold mechanism. I'm not really sure if the Stamp supports clock hold, vaguely recall the affirmative, but can't put my finger on an example. If it does, the correct command would be, best guessing,
I2CIN 0,%10000000,%11100011,[rawT.byte1,rawT.byte0]
tC = (rawT & $fffc) ** 17572 - 4685
There would be no I2COUT command. The I2CIN command takes care of everything. It writes the command %11100011 in the slot that is often called the address, and then it issues a repeated start and sends the %10000001 ID for reading, and then it it waits for the SHT21 to release the hold, and then it retrieves the high and low bytes of the data.
The SHT21 also allows for systems that don't support clock hold. (Many don't) . That code would look something like this:
I2COUT 0, %10000000,[%11110011] ' temperature, no hold master
Pause 100 . ' conversion at 14 bits can take up to 85ms
I2CIN 0, %10000000, [rawT,byte1, rawT.byte0]
tC = (rawT & $fffc) ** 17572 - 4685
In either case, use the rawT value in the math without shifting two bits left. (It is already left justified)
Mike
Note that the newer SHT31 works on a wider supply range, 2.4 to 5.5 volts. The word is, the SHT1x series is going to go EOL in the not too distant future, also deprecating the SHT21. Sensirion is pushing the SHT3x for new projects.
The SHT21 command for clock hold did not work. The SHT21 did hold the clock (as seen on a 'scope), but then nothing happened on the Stamp when the SHT21 released the hold.
Does anyone have SPIN2 code for SHT1x, SHT2x, SHT3x.........
Need SHT2x myself
Trying to port over Spin SHT1x to SPIN2 for practice learning but have no SHT1x to test it.
Thanks to JohnnyMac and others for spin to spin2 information.
There's no H in my name!
The attached object works with the 11 and 22 devices -- you have to declare the type in the start() method.