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 
11 #pragma once
12 
33 #include <errno.h>
34 #include <stdint.h>
35 
36 #include "periph/gpio.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
47 enum {
48  DHT_OK = 0,
51 };
52 
56 typedef struct {
57  uint16_t humidity;
58  uint16_t temperature;
59 } dht_data_t;
60 
64 typedef enum {
65  DHT11,
71 } dht_type_t;
72 
76 typedef struct {
77  gpio_t pin;
81 } dht_params_t;
82 
86 typedef struct {
89 } dht_t;
90 
106 int dht_init(dht_t *dev, const dht_params_t *params);
107 
130 int dht_read(dht_t *dev, int16_t *temp, int16_t *hum);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
Low-level GPIO peripheral driver interface definitions.
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:146
#define EIO
I/O error.
Definition: errno.h:97
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:91
dht_type_t
Device type of the DHT device.
Definition: dht.h:64
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:67
@ DHT21
DHT21 device identifier.
Definition: dht.h:69
@ DHT22
DHT22 device identifier.
Definition: dht.h:68
@ DHT11
Older DHT11 variants with either 1 °C or 0.1 °C resolution.
Definition: dht.h:65
@ AM2301
AM2301 device identifier.
Definition: dht.h:70
@ DHT_NOCSUM
checksum error
Definition: dht.h:49
@ DHT_TIMEOUT
communication timed out
Definition: dht.h:50
@ DHT_OK
all good
Definition: dht.h:48
Data type for storing DHT sensor readings.
Definition: dht.h:56
uint16_t humidity
relative humidity in deci-percent
Definition: dht.h:57
uint16_t temperature
temperature in deci-Celsius
Definition: dht.h:58
Configuration parameters for DHT devices.
Definition: dht.h:76
gpio_mode_t in_mode
input pin configuration, with or without pull resistor
Definition: dht.h:79
gpio_t pin
GPIO pin of the device's data pin.
Definition: dht.h:77
dht_type_t type
type of the DHT device
Definition: dht.h:78
Device descriptor for DHT sensor devices.
Definition: dht.h:86
dht_params_t params
Device parameters.
Definition: dht.h:87
dht_data_t last_val
Values of the last measurement.
Definition: dht.h:88