-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c051e9
commit c109b18
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
APPLICATION = driver_dht | ||
include ../Makefile.tests_common | ||
|
||
FEATURES_REQUIRED = periph_gpio | ||
|
||
# define default pin mappings for some boards: | ||
ifneq (,$(filter stm32f4discovery,$(BOARD))) | ||
export DHT_GPIO ?= GPIO_4 | ||
endif | ||
|
||
USEMODULE += dht | ||
|
||
ifneq (,$(DHT_TYPE)) | ||
CFLAGS += -DDHT_TYPE=$(DHT_TYPE) | ||
else | ||
# set random default | ||
CFLAGS += -DDHT_TYPE=DHT11 | ||
endif | ||
|
||
ifneq (,$(DHT_GPIO)) | ||
CFLAGS += -DDHT_GPIO=$(DHT_GPIO) | ||
else | ||
# set random default | ||
CFLAGS += -DDHT_GPIO=GPIO_0 | ||
endif | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2015 Ludwig Ortmann, Christian Mehlis | ||
* | ||
* 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 | ||
* | ||
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de> | ||
* @author Christian Mehlis <christian@m3hlis.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifndef DHT_TYPE | ||
#error "DHT_TYPE not defined" | ||
#endif | ||
|
||
#ifndef DHT_GPIO | ||
#error "DHT_GPIO not defined" | ||
#endif | ||
|
||
#include <stdio.h> | ||
|
||
#include "hwtimer.h" | ||
|
||
#include "dht.h" | ||
|
||
int main(void) | ||
{ | ||
dht_t dev; | ||
|
||
puts("DHT temperature and humidity sensor test application\n"); | ||
|
||
printf("Initializing DHT sensor at GPIO_%i... ", DHT_GPIO); | ||
if (dht_init(&dev, DHT_TYPE, DHT_GPIO) == 0) { | ||
puts("[OK]\n"); | ||
} | ||
else { | ||
puts("[Failed]"); | ||
return 1; | ||
} | ||
|
||
dht_data_t data; | ||
float temp, hum; | ||
while (1) { | ||
|
||
if (dht_read_raw(&dev, &data) == -1) { | ||
puts("error reading data"); | ||
} | ||
dht_parse(&dev, &data, &hum, &temp); | ||
printf("raw relative humidity: %i\nraw temperature: %i C\n", data.humidity, data.temperature); | ||
printf("relative humidity: %i\ntemperature: %i C\n", (int) hum, (int) temp); | ||
hwtimer_wait(HWTIMER_TICKS(2000 * 1000)); | ||
} | ||
|
||
return 0; | ||
} |