diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 709de94b322e4..f9dbedfeb0ec4 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -153,6 +153,15 @@ static int _parse_raw_values(dht_t *dev, uint8_t *data) * abs() of value (beware: this is not two's complement!) */ is_negative = data[BYTEPOS_TEMPERATURE_LOW] & 0x80; data[BYTEPOS_TEMPERATURE_LOW] &= ~0x80; + /* 2022-12 aosong.com data sheet uses interprets low bits as + * 0.01°C per LSB */ + if (!dev->params.lsb_is_hundreds && data[BYTEPOS_TEMPERATURE_LOW] > 9) { + /* in case of miss configuration */ + dev->params.lsb_is_hundreds = 1; + } + if (dev->params.lsb_is_hundreds) { + data[BYTEPOS_TEMPERATURE_LOW] /= 10; + } dev->last_val.temperature = data[BYTEPOS_TEMPERATURE_HIGH] * 10 + data[BYTEPOS_TEMPERATURE_LOW]; break; diff --git a/drivers/dht/include/dht_params.h b/drivers/dht/include/dht_params.h index 72307390e535f..b919b63f85154 100644 --- a/drivers/dht/include/dht_params.h +++ b/drivers/dht/include/dht_params.h @@ -37,12 +37,17 @@ extern "C" { #ifndef DHT_PARAM_TYPE #define DHT_PARAM_TYPE (DHT11) #endif +#ifndef DHT_PARAM_LSB_IS_HUNDREDS +#define DHT_PARAM_LSB_IS_HUNDREDS (0) +#endif #ifndef DHT_PARAM_PULL #define DHT_PARAM_PULL (GPIO_IN) #endif #ifndef DHT_PARAMS #define DHT_PARAMS { .pin = DHT_PARAM_PIN, \ .type = DHT_PARAM_TYPE, \ + .lsb_is_hundreds = \ + DHT_PARAM_LSB_IS_HUNDREDS, \ .in_mode = DHT_PARAM_PULL } #endif #ifndef DHT_SAULINFO diff --git a/drivers/include/dht.h b/drivers/include/dht.h index 212286ebdf238..504527c3d9b4c 100644 --- a/drivers/include/dht.h +++ b/drivers/include/dht.h @@ -75,6 +75,8 @@ typedef enum { typedef struct { gpio_t pin; /**< GPIO pin of the device's data pin */ dht_type_t type; /**< type of the DHT device */ + bool lsb_is_hundreds; /**< 2022-12 aosong.com data sheet uses interprets + * low bits as 0.01°C per LSB */ gpio_mode_t in_mode; /**< input pin configuration, with or without pull * resistor */ } dht_params_t;