Page 1 of 1

Conversion of signal outputs HTU21D Need help again please

Posted: Mon Aug 08, 2022 3:10 pm
by Amtor
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

Re: CONVERSION OF SIGNAL OUTPUTS HTU21D Need help again please

Posted: Mon Aug 08, 2022 3:42 pm
by Amtor
Updated
MQTT Data Source (ESP32) using TTGO board.fcfx
(59.11 KiB) Downloaded 59 times

Re: Conversion of signal outputs HTU21D Need help again please

Posted: Mon Aug 08, 2022 4:10 pm
by BenR
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.

Re: Conversion of signal outputs HTU21D Need help again please

Posted: Mon Aug 08, 2022 9:34 pm
by Amtor
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 "

Re: Conversion of signal outputs HTU21D Need help again please

Posted: Tue Aug 09, 2022 8:27 pm
by Amtor
Type Conversions component I wish I noticed it before.

Re: Conversion of signal outputs HTU21D Need help again please

Posted: Wed Aug 10, 2022 7:41 pm
by Amtor
It works.

Re: Conversion of signal outputs HTU21D Need help again please

Posted: Wed Aug 10, 2022 7:43 pm
by Amtor
Its working. Even on a phone app and on the PC App Dev