Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative temperatures #14

Closed
danielfaust opened this issue Nov 14, 2017 · 18 comments
Closed

Negative temperatures #14

danielfaust opened this issue Nov 14, 2017 · 18 comments
Labels

Comments

@danielfaust
Copy link
Contributor

danielfaust commented Nov 14, 2017

Have you tested this library with negative temperatures?

With a DHT22 I'm getting values like -3276.3°C for values slightly below 0°C (possibly for -0.7°C).

-3277.0°C is not reached, that one is then 0.0°C

@winlinvip
Copy link
Owner

Nop, I didn't test it. I'll try it in our refrigerator.

@danielfaust
Copy link
Contributor Author

Here is the code I'm using to work around this issue.

As I'm sending the data over BLE to an Android phone and the USB port of the ESP32 NodeMCU broke off (I'm using the library with that), making an on-device correction somewhat more laborious, i fixed it in the app which receives the data.

Before sending it to the phone I multiply with 100 and then cast to int, that makes the BLE decoding somewhat easier.

In the app I'm using the following to correct the issue:

int iTemp = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT32, 4);
if (iTemp < 0) {
    iTemp = -iTemp - 327700;
}
float fTemp = iTemp / 100.0;

@sulicz
Copy link

sulicz commented Dec 1, 2017

Hi, solution si:

    if (ptemperature) {
        if ( (temperature & 0x8000 )) {
          *ptemperature = (float) (temperature & 0x7FFF)/ -10.0;
        } else {
          *ptemperature = (float) temperature / 10.0;
        }
    }

in function SimpleDHT22::read2 and I changed all datatype short to uint16_t but datatype is may not a reason of problem.

@winlinvip
Copy link
Owner

Could u please file a PullRequest?

@danielfaust
Copy link
Contributor Author

I will look into it

@danielfaust
Copy link
Contributor Author

BTW, using a compressed gas duster (holding it upside down) can give you temps below the freezing point very quickly, then you can heat it up again with the fingers.

danielfaust added a commit to danielfaust/SimpleDHT that referenced this issue Jan 1, 2018
This commit fixes issue winlinvip#14
The MSB carries the sign information, which is filtered with `& 0x8000`. If the flag is present, the remainder will get multiplied by `-1`.
All the remaining bits contain the value and are filtered with `& 0x7FFF`.
winlinvip pushed a commit that referenced this issue Jan 2, 2018
This commit fixes issue #14
The MSB carries the sign information, which is filtered with `& 0x8000`. If the flag is present, the remainder will get multiplied by `-1`.
All the remaining bits contain the value and are filtered with `& 0x7FFF`.
@winlinvip
Copy link
Owner

Merged

@winlinvip
Copy link
Owner

Please fix it for DHT11.

@winlinvip winlinvip reopened this Jan 2, 2018
@danielfaust
Copy link
Contributor Author

danielfaust commented Jan 2, 2018

I don't have a DHT11 to test with. But since the DHT11 only works with temperatures equal to or above 0 °C, I think that sign flag never gets set. I preferred not to touch that code.

Good for 0-50°C temperature readings ±2°C accuracy

@winlinvip
Copy link
Owner

👌

@mapmelad
Copy link

Unfortunately still not displayed correctly :/

https://puu.sh/z23v3/7b8f96b37f.jpg

@danielfaust
Copy link
Contributor Author

@mapmelad on what device are you running it? For me this works on an ESP32, maybe this is device dependent? When you use a previous commit, what does it show?

@mapmelad
Copy link

mapmelad commented Jan 15, 2018

First, I obtained the values of the similarity -3277.0°C.
I used the fix:

if (ptemperature) {
        if ( (temperature & 0x8000 )) {
          *ptemperature = (float) (temperature & 0x7FFF)/ -10.0;
        } else {
          *ptemperature = (float) temperature / 10.0;
        }
    }

Then, after the fix I started getting the values 255, 254 and so on
If I delete in the code the minus sign *ptemperature = (float) (temperature & 0x7FFF)/ 10.0; , it displays the temperature correctly, but there is no minus sign in the output.

@danielfaust
Copy link
Contributor Author

Maybe this is due to the ArduinoBT -- which you're apparently using, judging from the screenshot -- being an 8 bit mcu while the ESP32 has a 32 bit cpu.

@winlinvip
Copy link
Owner

Should we reopen this issue? @danielfaust

@winlinvip
Copy link
Owner

Please test 1.0.9

@winlinvip
Copy link
Owner

image

I put DHT11 into refrigerator, its data is:

Sample DHT11 with RAW bits...
Sample RAW Bits: 0010 1100 0000 0000 0000 0001 0000 0000 0010 1101 
Sample OK: 1 *C, 44 H

Always above 0C.

@winlinvip
Copy link
Owner

winlinvip commented Aug 19, 2018

For DHT22:

Sample DHT22 with RAW bits...
Sample RAW Bits: 0000 0011 1110 0111 1000 0000 0101 1010 1100 0100 
Sample OK: -9.00 *C, 99.90 RH%
Sample DHT22 with RAW bits...
Sample RAW Bits: 0000 0010 1101 1101 1000 0000 1000 1000 1110 0111 
Sample OK: -13.60 *C, 73.30 RH%

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants