Conversion of signal outputs HTU21D Need help again please

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Amtor
Posts: 47
http://meble-kuchenne.info.pl
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Conversion of signal outputs HTU21D Need help again please

Post 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
Attachments
HTU21D SENSOR.pdf
(1.44 MiB) Downloaded 52 times
Temp sensor.JPG
Temp sensor.JPG (23.11 KiB) Viewed 1426 times
hum sensor.JPG
hum sensor.JPG (96.01 KiB) Viewed 1426 times
Last edited by Amtor on Mon Aug 08, 2022 4:10 pm, edited 2 times in total.

Amtor
Posts: 47
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Re: CONVERSION OF SIGNAL OUTPUTS HTU21D Need help again please

Post by Amtor »

Updated
MQTT Data Source (ESP32) using TTGO board.fcfx
(59.11 KiB) Downloaded 51 times
Last edited by Amtor on Wed Aug 10, 2022 4:58 pm, edited 4 times in total.

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Conversion of signal outputs HTU21D Need help again please

Post 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.

Amtor
Posts: 47
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Re: Conversion of signal outputs HTU21D Need help again please

Post 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 "

Amtor
Posts: 47
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Re: Conversion of signal outputs HTU21D Need help again please

Post by Amtor »

Type Conversions component I wish I noticed it before.

Amtor
Posts: 47
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Re: Conversion of signal outputs HTU21D Need help again please

Post by Amtor »

It works.
Attachments
the sensor.jpeg
the sensor.jpeg (88.23 KiB) Viewed 1300 times
the pc screen.jpeg
the pc screen.jpeg (34.43 KiB) Viewed 1300 times
phone app.jpeg
phone app.jpeg (22.56 KiB) Viewed 1300 times

Amtor
Posts: 47
Joined: Thu Dec 17, 2020 4:35 pm
Has thanked: 17 times
Been thanked: 14 times

Re: Conversion of signal outputs HTU21D Need help again please

Post by Amtor »

Its working. Even on a phone app and on the PC App Dev

Post Reply