===== 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.
By default it is configured for DHT22 sensors. This is configured via the SENS_DHT_TYPE define in the projdefs.h file for DHT11 or DHT22 sensor types.
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 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. See demo below for example.
- 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
WORD tmrFlashLed;
void __attribute__((interrupt,no_auto_psv)) _CNInterrupt(void)
{
WORD utick15bit_8us;
sensDht_isr_MACRO(utick15bit_8us);
}
int main(void) {
BYTE i;
debugPutString("\nThis is a test debug message from sensor_dht11_dht22");
DIR_SYSLED = OUTPUT_PIN;
sensDht_init(7, 3000, IOPORT_ID_NA, 0);
sensDht_addSensor(1, 8);
#if (nzINT_PRIORITY_TICK >= 6)
#error "Ensure Tick priority is smaller or equal to Interrupt On Change priority"
#endif
delay_ms(120);
while(1)
{
sensDht_task();
for(i=0; i<SENS_DHT_NUMBER_OF_SENSORS; i++) {
if (sensDht_hasNewTemperature(i)) {
sprintf(debugTempBuf,
"\nT%d: %d.%d",
i,
sensDht_getTemperatureInteger(i),
sensDht_getTemperatureDecimal(i));
debugPutString(debugTempBuf);
}
if (sensDht_hasNewHumidity(i)) {
sprintf(debugTempBuf,
"\nRH%d: %d.%d",
i,
sensDht_getHumidityInteger(i),
sensDht_getHumidityDecimal(i));
debugPutString(debugTempBuf);
}
}
LAT_SYSLED = !LAT_SYSLED;
}
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
debugPutString("\nHello");
}
debugPutString("\nReceived unknown debug message");
}
}
}
#endif