A simple library for reading data from a DHT22 sensor

Fork of lib_dht22 by Simon Cooksey

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dht22.h Source File

dht22.h

00001 /*
00002  * (C) The University of Kent and Simon Cooksey 2015.
00003  */
00004 
00005 #ifndef __DHT22_h_
00006 #define __DHT22_h_
00007 
00008 // We'll pick a point to decide if a signal is 1 or 0 from. 
00009 #define DHT22_SIGNAL_HIGH_LOW_BOUNDARY      50   // uS
00010 #define DHT22_START_BIT_TIME                500  // uS
00011 #define DHT22_START_BIT_RESPONSE            80   // uS
00012 
00013 typedef enum {
00014     EDGE_TYPE_FALLING,
00015     EDGE_TYPE_RISING,
00016 } edge_type_t;
00017 
00018 typedef struct {
00019     int temp;
00020     int humidity;
00021     uint8_t checksum;
00022 } DHT22_data_t;
00023 
00024 class DHT22 {
00025 public:
00026     DHT22(PinName pin)  : dht22_s(pin) { }
00027     void read(DHT22_data_t * data);
00028 private:
00029     DigitalInOut dht22_s;
00030 
00031     int wait_for_edge(edge_type_t type);
00032     void send_start();
00033     void await_start_response();
00034     int16_t read_word();
00035     uint8_t read_checksum();
00036 };
00037 
00038 #endif // __DHT22_h_