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

[Improvement] [DHT11] It is possible to get tenths of temperature #51

Open
martin-eden opened this issue Feb 12, 2022 · 3 comments
Open

Comments

@martin-eden
Copy link

For DHT11

While rewriting library for myself I've discovered that there are tenths of degrees Celsius transmitted in low nibble of second temperature byte. It is encoded in BCD, so hex values are in range 00..09.

@martin-eden
Copy link
Author

I'm using this "DHT11" sensor from eBay: https://www.ebay.com/itm/221914097856

Despite specified range 0..50 °C it can measure negative temperatures and have temperature granularity 0.1 °C. Temperature sign is stored in bit 7 of second temperature byte.

image

@DaleSchultz
Copy link

are you getting more accuracy than DHT11.read2() ?
(read2 takes floats)

@martin-eden
Copy link
Author

As you figured it out in another issues,

read2() returns floats but temperature granularity is 1.0, not 0.1.

*ptemperature = (int)(temperature>>8);

That's how I've done it:

  // 2nd temperature byte: tenths of temperature in low nibble in BCD.
  Temperature = (float) ((int16_t) Data[2] * 10 + (Data[3] & 0x0F)) / 10;
  // 2nd temperature byte: bit 7 is temperature sign.
  if (Data[3] & 0x80)
    Temperature = -Temperature;

That lines in my "scrapyard" unmaintained repo.

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

No branches or pull requests

2 participants