Hello,
usually is good to share also MbedOs version.
However, I tried that library with MbedOS 5.15.8 on Nucleo-F767ZI and output is OK
Temperature in Kelvin: 300.15, Celcius: 27.00, Farenheit 80.60
Humidity is 47.00, Dewpoint: 14.75, Dewpoint fast: 14.71
But you miss important part, you have to call readData()
function. Without it you will read 0 every time because the rest of functions only calculate a conversion of measured data.
#include "mbed.h"
#include "DHT.h"
DHT sensor(D4, DHT22);
int main()
{
int error = 0;
float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
while(1) {
thread_sleep_for(2000);
error = sensor.readData();
if (0 == error) {
c = sensor.ReadTemperature(CELCIUS);
f = sensor.ReadTemperature(FARENHEIT);
k = sensor.ReadTemperature(KELVIN);
h = sensor.ReadHumidity();
dp = sensor.CalcdewPoint(c, h);
dpf = sensor.CalcdewPointFast(c, h);
printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
} else {
printf("Error: %d\n", error);
}
}
}
For MbedOS6+ DHT - Fork of DHT component - https://os.mbed.com/teams… | Mbed also OK, but for that you also need to change printf lib in mbed_app.json
{
"target_overrides": {
"*": {
"target.printf_lib": "std"
}
}
}
BR, Jan