dht.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Ludwig Knüpfer,
3  * 2015 Christian Mehlis
4  * 2016-2017 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
31 #ifndef DHT_H
32 #define DHT_H
33 
34 #include <errno.h>
35 #include <stdint.h>
36 
37 #include "periph/gpio.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
48 enum {
49  DHT_OK = 0,
52 };
53 
57 typedef struct {
58  uint16_t humidity;
59  uint16_t temperature;
60 } dht_data_t;
61 
65 typedef enum {
66  DHT11,
72 } dht_type_t;
73 
77 typedef struct {
78  gpio_t pin;
82 } dht_params_t;
83 
87 typedef struct {
90 } dht_t;
91 
107 int dht_init(dht_t *dev, const dht_params_t *params);
108 
131 int dht_read(dht_t *dev, int16_t *temp, int16_t *hum);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* DHT_H */
Low-level GPIO peripheral driver interface definitions.
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:147
#define EIO
I/O error.
Definition: errno.h:98
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:91
dht_type_t
Device type of the DHT device.
Definition: dht.h:65
int dht_read(dht_t *dev, int16_t *temp, int16_t *hum)
get a new temperature and/or humidity value from the device
int dht_init(dht_t *dev, const dht_params_t *params)
Initialize a new DHT device.
@ DHT11_2022
New DHT11 variant with 0.01 °C resolution.
Definition: dht.h:68
@ DHT21
DHT21 device identifier.
Definition: dht.h:70
@ DHT22
DHT22 device identifier.
Definition: dht.h:69
@ DHT11
Older DHT11 variants with either 1 °C or 0.1 °C resolution.
Definition: dht.h:66
@ AM2301
AM2301 device identifier.
Definition: dht.h:71
@ DHT_NOCSUM
checksum error
Definition: dht.h:50
@ DHT_TIMEOUT
communication timed out
Definition: dht.h:51
@ DHT_OK
all good
Definition: dht.h:49
Data type for storing DHT sensor readings.
Definition: dht.h:57
uint16_t humidity
relative humidity in deci-percent
Definition: dht.h:58
uint16_t temperature
temperature in deci-Celsius
Definition: dht.h:59
Configuration parameters for DHT devices.
Definition: dht.h:77
gpio_mode_t in_mode
input pin configuration, with or without pull resistor
Definition: dht.h:80
gpio_t pin
GPIO pin of the device's data pin.
Definition: dht.h:78
dht_type_t type
type of the DHT device
Definition: dht.h:79
Device descriptor for DHT sensor devices.
Definition: dht.h:87
dht_params_t params
Device parameters.
Definition: dht.h:88
dht_data_t last_val
Values of the last measurement.
Definition: dht.h:89