2015-05-15 23:18:32 +02:00
|
|
|
/*
|
2015-09-27 18:58:30 +02:00
|
|
|
* Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis
|
2016-01-21 18:42:48 +01:00
|
|
|
* 2016 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"
|
2015-05-15 23:18:32 +02:00
|
|
|
#include "dht.h"
|
2016-01-21 15:31:13 +01:00
|
|
|
#include "dht_params.h"
|
|
|
|
|
|
|
|
extern dht_t dht_devs[];
|
2015-05-15 23:18:32 +02:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
puts("DHT temperature and humidity sensor test application\n");
|
|
|
|
|
2016-01-21 15:31:13 +01:00
|
|
|
/* periodically read temp and humidity values */
|
2015-05-15 23:18:32 +02:00
|
|
|
while (1) {
|
2016-01-21 15:31:13 +01:00
|
|
|
for (unsigned i = 0; i < DHT_NUMOF; i++) {
|
|
|
|
dht_t *dev = &dht_devs[i];
|
2016-01-21 18:42:48 +01:00
|
|
|
int16_t temp, hum;
|
|
|
|
int16_t dec_temp, dec_hum, int_temp, int_hum;
|
2016-01-21 15:31:13 +01:00
|
|
|
|
2016-01-21 18:42:48 +01:00
|
|
|
if (dht_read(dev, &temp, &hum) == -1) {
|
2016-01-21 15:31:13 +01:00
|
|
|
puts("error reading data");
|
2016-01-21 18:42:48 +01:00
|
|
|
continue;
|
2016-01-21 15:31:13 +01:00
|
|
|
}
|
2016-01-21 18:42:48 +01:00
|
|
|
|
|
|
|
/* split up values into integral and fractional parts for nicer
|
|
|
|
* printing
|
|
|
|
* TODO: this should be done in some kind of library... */
|
|
|
|
int_temp = temp / 10;
|
|
|
|
dec_temp = temp - (int_temp * 10);
|
|
|
|
int_hum = hum / 10;
|
|
|
|
dec_hum = hum - (int_hum * 10);
|
|
|
|
|
2016-08-21 16:54:22 +02:00
|
|
|
printf("DHT device #%u - ", i);
|
2016-01-21 18:42:48 +01:00
|
|
|
printf("temp: %i.%i°C, ", int_temp, dec_temp);
|
|
|
|
printf("relative humidity: %i.%i%%\n", int_hum, dec_hum);
|
|
|
|
|
2016-01-21 15:31:13 +01:00
|
|
|
xtimer_usleep(2000 * MS_IN_USEC);
|
2015-05-15 23:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|