Hello
I have the sensor returning the two Bytes correctly I think but can't figure out how to put this calculation into the box.
Also how to set the last 2 bits of the LSB to zero. Would I just shift the number left twice.
I think I need to do some shifting to add the two bytes together, not just had them up.
CONVERSION OF SIGNAL OUTPUTS
Default resolution is set to 12-bit relative humidity and 14-bit temperature readings. Measured data are
transferred in two byte packages, i.e. in frames of 8-bit length where the most significant bit (MSB) is transferred
first (left aligned). Each byte is followed by an acknowledge bit. The two status bits, the last bits of LSB, must be
set to ‘0’ before calculating physical values.
Thanks very much for any help.
I expect it child's play to you lads
All the best
Mark
Conversion of signal outputs HTU21D Need help again please
-
- Posts: 50
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 17, 2020 4:35 pm
- Has thanked: 18 times
- Been thanked: 15 times
Conversion of signal outputs HTU21D Need help again please
- Attachments
-
- HTU21D SENSOR.pdf
- (1.44 MiB) Downloaded 247 times
-
- Temp sensor.JPG (23.11 KiB) Viewed 3004 times
-
- hum sensor.JPG (96.01 KiB) Viewed 3004 times
Last edited by Amtor on Mon Aug 08, 2022 4:10 pm, edited 2 times in total.
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Conversion of signal outputs HTU21D Need help again please
Hello,
To set the lower 2 or 4 bits to 0 you can just do some masking, looks like shifting may also divide down the data.
TempReg = TempReg & 0xFFFC
HumReg = HumReg & 0xFFF0
Then for the calc maybe do something like this.
FloatTemp = TempReg / 65536.0
FloatTemp = FloatTemp * 175.72
FloatTemp = FloatTemp - 46.85
FloatHum = HumReg / 65536.0
FloatTemp = FloatTemp * 125.0
FloatTemp = FloatTemp - 6.0
Hope this helps.
To set the lower 2 or 4 bits to 0 you can just do some masking, looks like shifting may also divide down the data.
TempReg = TempReg & 0xFFFC
HumReg = HumReg & 0xFFF0
Then for the calc maybe do something like this.
FloatTemp = TempReg / 65536.0
FloatTemp = FloatTemp * 175.72
FloatTemp = FloatTemp - 46.85
FloatHum = HumReg / 65536.0
FloatTemp = FloatTemp * 125.0
FloatTemp = FloatTemp - 6.0
Hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: Conversion of signal outputs HTU21D Need help again please
Thanks very much for your help.
I've put something in that seems to be giving a reasonable result.
It's joining the upper and lower bytes together I'm not sure how to do.
I've just shifted the upper byte up 8 places I think and and'ed off the last 2 bits
from the lower byte and then just added them together.
I'm sure there must be a mistake in there somewhere.
The thing I thought I'd have trouble with the MQTT part works lovely.
thanks
HumRegUpper = Upper_Byte << 8
HumRegLower = Lower_Byte & 0xFFF0
HumReg = HumRegUpper + HumRegLower
FloatHum = HumReg / 65536.0
FloatHum = FloatHum * 125.0
FloatHum = FloatHum - 6.0
Humidity = FloatToString$ (FloatHum)
Display_Hum = Humidity + " % Humidity "
I've put something in that seems to be giving a reasonable result.
It's joining the upper and lower bytes together I'm not sure how to do.
I've just shifted the upper byte up 8 places I think and and'ed off the last 2 bits
from the lower byte and then just added them together.
I'm sure there must be a mistake in there somewhere.
The thing I thought I'd have trouble with the MQTT part works lovely.
thanks
HumRegUpper = Upper_Byte << 8
HumRegLower = Lower_Byte & 0xFFF0
HumReg = HumRegUpper + HumRegLower
FloatHum = HumReg / 65536.0
FloatHum = FloatHum * 125.0
FloatHum = FloatHum - 6.0
Humidity = FloatToString$ (FloatHum)
Display_Hum = Humidity + " % Humidity "
Re: Conversion of signal outputs HTU21D Need help again please
It works.
- Attachments
-
- the sensor.jpeg (88.23 KiB) Viewed 2878 times
-
- the pc screen.jpeg (34.43 KiB) Viewed 2878 times
-
- phone app.jpeg (22.56 KiB) Viewed 2878 times