	*** OLIMEX demo project for the MOD-ZIGBEE-PIR ***

1. Requirements
	- At least 2 MOD-ZIGBEE-x demo boards by Olimex (the coordinator board may a MOD-ZIGBEE_revB, MOD-ZIGBEE or another MOD-ZIGBEE-PIR)
	- RS232 level converter or adapter board (ex. MOD-USB-RS232 by Olimex or a FTDI chip)
	- Compatible debugger, for example PICkit3 or ICD2
	- MPLAB IDE by Microchip with installed MPLAB C18 Compiler (version MPLAB.X also supported)
	- Terminal program (Hyper Terminal, PuTTY, etc.)
	- Power source - 2 type AA batteries or external source
	
2. Description
	This sample project demonstrates the functionality of the onboard processor, the radio transceiver, the thermometer and PIR sensor. 

	The demo uses ZigBee stack library provided by Microchip. One of the devices uses the project 'Coordinator' and is configured as a ZigBee coordinator that sets up a network and wait for devices to connect. The other type of device is RFD (this should be a MOD-ZIGBEE-PIR), uses the other project named 'RFD' and upon startup it tries to connect to the coordinator. Upon successful connection the RFD falls to sleep. When the user presses one of the buttons (not the Reset button, of course) on the board the RFD wakes up and sends a message containing specific information:
	- B1 sends the currently measured temperature by the onboard thermometer chip.
	
	- B2 sends the name of the friendly device (configured in compile time in zigbee.def)
	
	PIR sensor also sends messages to the coordinator when thermal movement is detected in the visible area around the board.
	
	The messages should be received by the coordinator and when decoded the Coordinator prints one of these messages on its UART console (please see section 3 on how to implement the console), the LED2 on the coordinator is also toggled when a message is received.
	Messages are interpreted like this:
	- B1 message: - From Address XXXX-> Tempr: XX.XXXXoC
	- B2 message: - From Address XXXX-> Name: DEVICE1
	- PIR message: - From Address XXXX-> PIR TRIGGERED
	
	The user can control whether messages are received or ignored by pressing B2 on the coordinator. LED1 indicates the current state. Upon powerup message reception is disabled.
	
	Upon startup the Coordinator forms a network with PAN ID 0x3332 on channel 26, LED2 is lit and the program starts waiting for client devices to connect. Status messages are printed over UART and can be displayed on a terminal program on a PC (please see next chapter). The Coordinator is configured to accept at default but this can be changed through the console menu (see below). The Coordinator accepts connections from any device that requests joining but will only recognize messages about name, temperature and PIR activity of end devices. Received and recognized messages are printed on the terminal and LED2 toggles at any successful reception. Here is a sample terminal log from the operation of a Coordinator:
	
-----------------------------------------------------------------------------------------
********************************
MicroChip ZigBee2006(TM) Stack  v2.0-2.6.0a Coordinator

Transceiver-MRF24J40

Trying to start network...
PAN 0x3332 started successfully.
Joining permitted.

     1: Enable/Disable Joining by Other Devices
     2: Enable/Disable messages from Group 4
     3: Dump Neighborhood Information
Enter a menu choice:


-----------------------------------------------------------------------------------------
	
	A couple of options are available on the console printed above. Those should be self explanatory.
	
	Upon startup an End Device starts searching for a network with parameters matching those of the coordinator. If such a network is not found the device reattempts connecting. When a suitable network is found (formed by the Coordinator) the device joins it and enters deep sleep mode. The sleep may be prematurely terminated by a press of any of the two buttons or PIR interrupt.
	
3. How to setup Coordinator to print messages:
	MOD-ZIGBEE boards provide UART with TTL levels. In order to visualize console on a PC screen you need a way to communicate with the PC. This can be accomplished via a physical COM port (rarely available on modern PCs) and a simple level shifter such as MAX232. Another way to get things going is to use a virtual COM port solution such as a USB<->RS232 bridge (that is our MOD-USB-RS232 board) that directly accepts TTL level signals and is installed as a COM port on the side of the PC. In either way you will need to open the COM port with a terminal program such as PuTTY and the following settings: 19200-8N1.

	The easiest hardware configuration is to have available MOD-ZIGBEE rev.B board and a MOD-USB-RS232 board. Then you will just have to configure MOD-USB-RS232 in host mode (TX on pin 3 of the UEXT, RX on pin 4), plug one into the other and that is all.
	
	Having another MOD-ZIGBEE-PIR board available requires an UEXT cable and the MOD-USB-RS232 configured opposite to the MOD-ZIGBEE-PIR (each of the boards has the Tx and Rx pins configurable).
	
	In the case of MOD-ZIGBEE you will have to manually connect pins RC6 (TX as seen from the MCU), and RC7 (RX as seen from the MCU) and GND of the MOD-ZIGBEE board to the respective pins of the level converter or protocol bridge.

4. How to use this demo
	The board ships with demo firmware for the End Device preinstalled which has the same functionality as in this project at time of manufacture (maybe there is an update to the demo when you read this).
	
	To download the firmware to the board you need some sort of programmer/debugger compatible with the PIC18F26K20 processor.
	
	The fastest possible way to get things running is to download the precompiled hex file to the processor memory. The file needed for the Coordinator is called "Coordinator_Prebuilt.hex" and for end devices it is "RFD_Prebuilt.hex", both located in the Prebuilt/. Import this file in MPLAB and select processor PIC18F26K20.

	IMPORTANT NOTE:
		Due to specifications of ZigBee and the lack of unique hardware address in the radio chips of devices, programming more than one device with the same hex file will result in identical and indistinguishable devices. Such devices will get same addresses from the Coordinator and behave the same way. I order to deal with this situation you will have to edit the 'zigbee.def' (section MAC address).
	
	An alternative is to open the workspace MOD-ZIGBEE-PIR.mcw in MPLAB, compile it and then debug the application. This sample workspace may also be your starting point in developing new applications using the board. Please note that MPLAB.X is also supported (projects inside 'PIC18RFD.X' and 'PIC18Coordinator.X')
	
	Build info:
		MPLAB IDE v8.63 (MPLAB.X beta 7.02)
		MPLAB C18 v3.40
		ZigBee2006Res-v2.0-2.6c
		
	Debugger used:
		PICKit3 by Microchip

5. Further reading
	User's manual for the MOD-ZIGBEE-PIR board. Also feel free to consult all documents released by Microchip regarding their ZigBee support and related PIC18 support documents and application notes.

6. Support
	http://www.microchip.com/
	http://www.olimex.com/dev/
	
Last edit
	17 Oct 2011
