mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
a582da1f31
- many backports from @maribu's IRQ based implementation (#18591) - use of ztimer and errno.h - separation of dht_read() steps into functions for better readability - reintroduction of DHT11/DHT22 differentiation - sensor presence checking in dht_init() - default input mode changed to open drain - AVR support without platform-specific handling by avoiding ztimer_spin() and using the overflow of an 8-bit variable as a pre-timeout to minimize time-consuming ztimer_now() calls - add a new DHT11_2022 type for 0.01 °C resolution devices - data caching removed
65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
/*
|
|
* Copyright (C) 2015 Ludwig Knüpfer, Christian Mehlis
|
|
* 2016-2017 Freie Universität Berlin
|
|
*
|
|
* 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 Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "dht.h"
|
|
#include "dht_params.h"
|
|
#include "time_units.h"
|
|
#include "ztimer.h"
|
|
|
|
#define DELAY (2 * US_PER_SEC)
|
|
|
|
int main(void)
|
|
{
|
|
dht_t dev;
|
|
int16_t temp, hum;
|
|
|
|
puts("DHT temperature and humidity sensor test application\n");
|
|
|
|
/* 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;
|
|
}
|
|
|
|
/* periodically read temp and humidity values */
|
|
while (1) {
|
|
ztimer_sleep(ZTIMER_USEC, DELAY);
|
|
|
|
if (dht_read(&dev, &temp, &hum) != DHT_OK) {
|
|
puts("Error reading values");
|
|
continue;
|
|
}
|
|
|
|
printf("DHT values - temp: %d.%d°C - relative humidity: %d.%d%%\n",
|
|
temp/10, temp%10, hum/10, hum%10);
|
|
}
|
|
|
|
return 0;
|
|
}
|