===== Description =====
This demo shows how to communicate with the DHT11 and DHT22 1-Wire interface chip, using the nz_sensDht.h and nz_sensDht.c driver. It uses non-blocking (asynchronous) functions, meaning all processing is done in background interrupts and fibers.
It also flashes the system LED.
To add DHT22 support to a project, the following must be done:
- Add nz_sensDht.c to the project, this is the main DHT22 driver file.
- 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 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!
This demo can be used with any SBC66 Netcruzer board with an USB Port (not USB Host). It uses USB Commands and Debug Messages sent and received via the Netcruzer USB Terminal app to communicate with board.
Additionally this demo also implements debugging via the USB port and the Netcruzer USB Terminal App. During the program various debug messages are written, which will be displayed on the "Netcruzer USB Terminal" (running on a PC connected to the target board's USB port). This demo also monitors the USB port for Debug messages send to us.
- If "hi" is received, it replies with "Hello"
Use the "Netcruzer USB Terminal" App to send and receive USB Debug messages. It can be downloaded here: https://netcruzer.com/usbterminal/
===== Required Hardware =====
The project requires a SBC66 Netcruzer board with an USB Port (not USB Host), like the SBC66ZL for example. Additionally a DHT11 or DHT22 Sensor has to be connected to any of the SBC66 port pins.
===== Building Project =====
This project is located in the "src/demos/sensors/sensor_dht11_dht22" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ZL_R1" for the SBC66ZL Revision 1 board. For details click here
===== Programming Board =====
After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.
===== File History =====
2014-02-10, David H. (DH):
#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h"
#define MY_DEBUG_LEVEL DEBUG_LEVEL_INFO
TICK16 tmrFlashLed;
TICK16 tmrReadSensor;
int main(void) {
debugPutString("\nThis is a test debug message from sensor_dht11_dht22_block");
DIR_SYSLED = OUTPUT_PIN;
sensDht_init(3000, 1, 0);
sensDht_addSensor(7);
sensDht_addSensor(8);
delay_ms(120);
while(1)
{
sensDht_task();
if (sensDht_isReady()) {
if (sensDht_read(SENS_DHT_TYPE_DHT22, 7) == 0) {
sprintf(debugTempBuf,
"\nTemperature(7)=%d.%d",
sensDht_getTemperatureInteger(),
sensDht_getTemperatureDecimal());
debugPutString(debugTempBuf);
sprintf(debugTempBuf,
", Humidity=%d.%d",
sensDht_getHumidityInteger(),
sensDht_getHumidityDecimal());
debugPutString(debugTempBuf);
}
else {
debugPutString("\nError reading DHT22 on port 7!");
}
if (sensDht_read(SENS_DHT_TYPE_DHT22, 8) == 0) {
sprintf(debugTempBuf,
"\nTemperature(8)=%d.%d",
sensDht_getTemperatureInteger(),
sensDht_getTemperatureDecimal());
debugPutString(debugTempBuf);
sprintf(debugTempBuf,
", Humidity=%d.%d",
sensDht_getHumidityInteger(),
sensDht_getHumidityDecimal());
debugPutString(debugTempBuf);
}
else {
debugPutString("\nError reading DHT22 on port 8!");
}
}
}
LAT_SYSLED = !LAT_SYSLED;
}
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
debugPutString("\nHello");
}
debugPutString("\nReceived unknown debug message");
}
}
}
#endif