DHT11 readout library
Macros | Functions
dht11.h File Reference

dht11.h Header file for the DHT11 readout library
The DHT11 is a temperature and humidity sensor implementing its own 1-wire serial protocol. The functions of this library allow to start a measurement and to extract human readable results from the serial data stream sent by the DHT11
Copyright U. Raich Oct. 2017
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017 It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html More...

#include <stdbool.h>
#include <sys/timeb.h>
#include <time.h>
#include <strings.h>
Include dependency graph for dht11.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DHT11_GPIO_PIN   0
 
#define DHT11_PROTOCOL_TIMEOUT   100
 
#define DHT11_PROTOCOL_SIZE   800
 
#define DHT11_PROTOCOL_SIZE_MARGIN   200
 
#define DHT11_SUCCESS   0
 
#define DHT11_MISSING_INIT   -1
 
#define DHT11_NO_MEAS_YET   -2
 
#define DHT11_NO_VALID_MEAS_YET   -3
 
#define DHT11_MEM_ALLOC_ERROR   -4
 
#define DHT11_PROTOCOL_ERROR   -5
 
#define DHT11_BAD_CHECKSUM   -6
 
#define DHT11_BAD_TIME_STAMP   -10
 

Functions

void dht11SetDebug (bool)
 switches debug mode on or off More...
 
int dht11Measurement (void)
 make a measurement and saves the data in an internal array returns DHT11_SUCCESS if successful DHT11_MISSING_INIT if dht11Init has not been called before
 
void dht11PrintError (int)
 prints an error message in human understandable form More...
 
void dht11Init (void)
 connects to the wiringPi library
 
int dht11GetTemperature (void)
 returns the measured temperature value in degrees C More...
 
int dht11GetValidTemperature (void)
 returns the measured temperature value in degrees C More...
 
int dht11GetHumidity (void)
 returns the measured humidity value in % More...
 
int dht11GetValidHumidity (void)
 returns the measured humidity value in % More...
 
time_t dht11GetMeasTimeStamp (void)
 returns the time stamp of the last measurement More...
 
time_t dht11GetValidMeasTimeStamp (void)
 returns the time stamp of the last valid measurement More...
 
int dht11GetRawData (int *)
 returns the measured data independent of the checksum test More...
 
int dht11GetValidRawData (int *)
 returns the measured data which were checked by the checksum test More...
 
int dht11GetChecksum (void)
 returns the checksum as calculated from the data
 
int dht11GetDeviceChecksum ()
 returns the checksum as read from the dht11
 

Detailed Description

dht11.h Header file for the DHT11 readout library
The DHT11 is a temperature and humidity sensor implementing its own 1-wire serial protocol. The functions of this library allow to start a measurement and to extract human readable results from the serial data stream sent by the DHT11
Copyright U. Raich Oct. 2017
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017 It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html

Function Documentation

int dht11GetHumidity ( void  )

returns the measured humidity value in %

Returns
The last humidity data measured independent of the checksum result System interrupts may disturb reading of the data stream from the DHT11 and corrupt the data. This is checked for by comparing the calculated checksum with the one sent by the DHT11. This call returns the humidity data without the checksum test.
time_t dht11GetMeasTimeStamp ( void  )

returns the time stamp of the last measurement

Returns
The time stamp independent of the checksum test
int dht11GetRawData ( int *  rawData)

returns the measured data independent of the checksum test

Parameters
int*rawData is a pointer to an integer array of a size of at least DHT11_PROTOCOL_SIZE integer values. If a NULL pointer is passed to the routine, it will allocate memory space big enough to hold the data. In this case the caller must free the allocated memory after use
int dht11GetTemperature ( void  )

returns the measured temperature value in degrees C

Returns
The last temperature measured independent of the checksum result System interrupts may disturb reading of the data stream from the DHT11 and corrupt the data. This is checked for by comparing the calculated checksum with the one sent by the DHT11. This call returns the temperature data without the checksum test.
int dht11GetValidHumidity ( void  )

returns the measured humidity value in %

Returns
The last temperature measured with correct checksum this returns valid temperature data
time_t dht11GetValidMeasTimeStamp ( void  )

returns the time stamp of the last valid measurement

Returns
The time stamp of the last measurement having passed the checksum test. You can print the time stamp in a humanly readable format with:
timeStamp = dht11GetMeasTimeStamp();
printf("%s\n",ctime(&timeStamp));
int dht11GetValidRawData ( int *  rawData)

returns the measured data which were checked by the checksum test

Parameters
int*rawData is a pointer to an integer array of a size of at least DHT11_PROTOCOL_SIZE integer values. If a NULL pointer is passed to the routine, it will allocate memory space bit enough to hold the data. In this case the caller must free the allocated memory after use
int dht11GetValidTemperature ( void  )

returns the measured temperature value in degrees C

Returns
The last temperature measured with correct checksum this returns valid temperature data
void dht11PrintError ( int  err)

prints an error message in human understandable form

Parameters
anerror code returned by the library
void dht11SetDebug ( bool  onOff)

switches debug mode on or off

Parameters
onOfftrue: switches debug mode on
false: switches debug mode off