2015-05-15 23:18:32 +02:00
|
|
|
/*
|
2015-09-27 18:58:30 +02:00
|
|
|
* Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis
|
2017-02-07 09:59:30 +01:00
|
|
|
* 2016-2017 Freie Universität Berlin
|
2015-05-15 23:18:32 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test application for the dht humidity and temperature sensor driver
|
|
|
|
*
|
2015-09-27 18:58:30 +02:00
|
|
|
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
2015-05-15 23:18:32 +02:00
|
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
2016-01-21 18:42:48 +01:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2015-05-15 23:18:32 +02:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-09-03 18:53:45 +02:00
|
|
|
#include "xtimer.h"
|
2017-02-07 09:59:30 +01:00
|
|
|
#include "timex.h"
|
|
|
|
#include "fmt.h"
|
2015-05-15 23:18:32 +02:00
|
|
|
#include "dht.h"
|
2016-01-21 15:31:13 +01:00
|
|
|
#include "dht_params.h"
|
|
|
|
|
2017-02-07 09:59:30 +01:00
|
|
|
#define DELAY (2 * US_PER_SEC)
|
2015-05-15 23:18:32 +02:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2017-02-07 09:59:30 +01:00
|
|
|
dht_t dev;
|
|
|
|
int16_t temp, hum;
|
|
|
|
|
2015-05-15 23:18:32 +02:00
|
|
|
puts("DHT temperature and humidity sensor test application\n");
|
|
|
|
|
2017-02-07 09:59:30 +01:00
|
|
|
/* initialize first configured sensor */
|
|
|
|
printf("Initializing DHT sensor...\t");
|
|
|
|
if (dht_init(&dev, &dht_params[0]) == DHT_OK) {
|
|
|
|
puts("[OK]\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("[Failed]");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-21 15:31:13 +01:00
|
|
|
/* periodically read temp and humidity values */
|
2015-05-15 23:18:32 +02:00
|
|
|
while (1) {
|
2017-02-07 09:59:30 +01:00
|
|
|
if (dht_read(&dev, &temp, &hum) != DHT_OK) {
|
|
|
|
puts("Error reading values");
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-21 18:42:48 +01:00
|
|
|
|
2021-11-20 14:48:07 +01:00
|
|
|
printf("DHT values - temp: %d.%d°C - relative humidity: %d.%d%%\n",
|
|
|
|
temp/10, temp%10, hum/10, hum%10);
|
2016-01-21 18:42:48 +01:00
|
|
|
|
2017-02-07 09:59:30 +01:00
|
|
|
xtimer_usleep(DELAY);
|
2015-05-15 23:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|