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

[DHT22] modified interpretation of temperature values in byte 2 and 3, such that negative temperature values are handled correctly #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bkormann80
Copy link

This pull request solves the issue described in #221.

Negative temperature values from a DHT22 sensor can be interpreted as a 16 bit signed integer (short). There is no additional differentiation needed.

float DHT::readTemperature(bool S, bool force) {
  float f = NAN;
  short s = 0;
...
    case DHT22:
      s = ((short) data[2]) << 8 | data[3];
      f = s * 0.1;
      if (S) {
        f = convertCtoF(f);
      }
      break;
... 

The patch was successfully tested using five different DHT22 sensors on an Arduino UNO and an ESP8266 at positive and negative temperatures.

…hat negative temperature values are handled correctly
@dhalbert dhalbert requested a review from caternuson December 29, 2024 17:43
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

Successfully merging this pull request may close these issues.

1 participant