Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_sensDht.h File Reference

Functions for DHT11 and DHT22 Temperature and Humidity Sensors. More...

Go to the source code of this file.

Macros

#define SENS_DHT_NUMBER_OF_SENSORS   ( 0 )
 

Detailed Description

Functions for DHT11 and DHT22 Temperature and Humidity Sensors.

Author
Modtronix Engineering
Compiler:
MPLAB XC16

Description

Functions for reading the DHT11 and DHT22 temperature and humidity values. The SENS_DHT_STARTUP_READ_DELAY value will define the initial delay before reading the first values, and is 5 seconds by default.

The SENS_DHT_AUTO_READ_PERIOD value will define how long to delay between reading the sensor. The default is 5000ms, meaning the temperature and humidity will automatically be read every 5 seconds. If this value is set to 0, automatic read are disabled. In this case, the sensDht_startRead() function has to be called to start the reading process, which is performed in the background.

Configuration

The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.

// *********************************************************************
// ------------ DHT Sensor Configuration (from nz_sensDht.h) -------------
// *********************************************************************
// Timeout 100ms
#define SENS_DHT_TIMEOUT ( 100 ) //[-DEFAULT-]
// Initial read delay 2 seconds (2000ms)
#define SENS_DHT_STARTUP_READ_DELAY ( 5000 ) //[-DEFAULT-]
// Automatically read every 5 seconds (5000ms), set to 0 to disable auto read!
#define SENS_DHT_AUTO_READ_PERIOD ( 5000 ) //[-DEFAULT-]
// Size of Pin Array read buffer, must be 4,8,16,32,64,128 or 256. Use 256 for optimum speed!
#define SENS_DHT_PIN_ARRAY_SIZE ( 128 ) //[-DEFAULT-]
// Sensor Type, 1=DHT11, 2=DHT22
#define SENS_DHT_TYPE ( 2 ) //[-DEFAULT-]
// Number of Sensors, set to 0 to disable DHT Sensor module
#define SENS_DHT_NUMBER_OF_SENSORS ( 1 ) //[-DEFAULT-]

Usage

To use this module, the following must be done:

  • Include nz_sensDht.h in the c file it is used in.
  • Add nz_sensDht.c to the MPLAB project, this is the main DHT22 driver file.
  • The project must have "Netcruzer RTOS Fibers" enabled, see Usage when only using Fibers.
  • The following additional files are required by nz_sensDht.c, and must be added to the project: nz_helpers.c, nz_ioPorts.c, nz_netcruzer.c
  • Add sensDht_task() to main loop. For example: sensDht_init(36); //Initialize using port 36 (old port name Y6) for DHT Sensor while(1) { nzSysTaskDefault(); //Main netcruzer task, call in main loop. sensDht_task(); //DHT22 Task }
  • In code, configure interrupt for pin used by DHT Sensor. In the ISR for this interrupt, call sensDht_isr_MACRO() macro.
  • In projdefs.h, do any DHT22 or other configuration required. This is done by copying the configuration section from the *.h files to projdefs.h. Nothing required, defaults will work!
  • All done! Can now use DHT22.h driver functions!

For details, see DHT22 and DHT11 demos in "../src/demos/sensors/" folder of Netcruzer Download.

Software License Agreement

The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.

THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

File History

2014-01-02, David H. (DH):

  • Initial version