Contiki-NG
Loading...
Searching...
No Matches
dht22.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, Zolertia - http://www.zolertia.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32/*---------------------------------------------------------------------------*/
33/**
34 * \addtogroup zoul-sensors
35 * @{
36 *
37 * \defgroup zoul-dht22 DHT22 temperature and humidity sensor
38 *
39 * Driver for the DHT22 temperature and humidity sensor
40 * @{
41 *
42 * \file
43 * Header file for the DHT22 temperature and humidity sensor
44 */
45/*---------------------------------------------------------------------------*/
46#include "lib/sensors.h"
47/*---------------------------------------------------------------------------*/
48#ifndef DHT22_H_
49#define DHT22_H_
50/* -------------------------------------------------------------------------- */
51/**
52 * \name DHT22 default pin and port
53 * @{
54 */
55#ifdef DHT22_CONF_PIN
56#define DHT22_PIN DHT22_CONF_PIN
57#else
58#define DHT22_PIN 5
59#endif
60#ifdef DHT22_CONF_PORT
61#define DHT22_PORT DHT22_CONF_PORT
62#else
63#define DHT22_PORT GPIO_A_NUM
64#endif
65/** @} */
66/* -------------------------------------------------------------------------- */
67/**
68 * \name DHT22 available commands
69 * @{
70 */
71#define DHT22_READ_TEMP 0x01
72#define DHT22_READ_HUM 0x02
73#define DHT22_READ_ALL 0x03
74/** @} */
75/* -------------------------------------------------------------------------- */
76/**
77 * \name DHT22 return types
78 * @{
79 */
80#define DHT22_ERROR (-1)
81#define DHT22_SUCCESS 0x00
82#define DHT22_BUSY 0xFF
83/** @} */
84/* -------------------------------------------------------------------------- */
85/**
86 * \name DHT22 constants
87 * @{
88 */
89#define DHT22_BUFFER 5 /**< Buffer to store the samples */
90#define DHT22_COUNT 8 /**< Minimum ticks to detect a "1" bit */
91#define DHT22_MAX_TIMMING 85 /**< Maximum ticks in a single operation */
92#define DHT22_READING_DELAY 1 /**< 1 us */
93#define DHT22_READY_TIME 40 /**< 40 us */
94#define DHT22_START_TIME (RTIMER_SECOND / 50) /**< 20 ms */
95#define DHT22_AWAKE_TIME (RTIMER_SECOND / 4) /**< 250 ms */
96/** @} */
97/* -------------------------------------------------------------------------- */
98/**
99 * \name DHT22 auxiliary functions
100 * @{
101 */
102int16_t dht22_read_all(int16_t *temperature, int16_t *humidity);
103/** @} */
104/* -------------------------------------------------------------------------- */
105#define DHT22_SENSOR "DHT22 sensor"
106/* -------------------------------------------------------------------------- */
107extern const struct sensors_sensor dht22;
108/* -------------------------------------------------------------------------- */
109#endif /* DHT22_H_ */
110/* -------------------------------------------------------------------------- */
111/**
112 * @}
113 * @}
114 */