This post will provide a working as well as practical example of how to interface Xbee modules with PIC microcontrollers. The purpose of writing this page is to show two very basic things. One I am having two circuits one is based on practical example and second is based on Proteus simulation. This will also help us to understand that simulation and practical things are quite similar if you have proper experimental approach although practically doing things has its own importance. But what I am writing to this blog I have done that practically when I was in university. And secondly this post will answer “How to communicate between two systems wirelessly, placed at a certain distance?”
You may download code and Proteus Simulation from the download section at the bottom of this post. I am using MPLAB X IDE, C30 Compiler and Proteus Simulation on v8.0. This code is written in C Language and will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing the code.
Before proceeding further I supposed that you know following. If not then please go through following pages first.
· How to use UART module for 16Bit PIC microcontrollers (Clickhere).
· How to interface LCD with 16Bit PIC microcontrollers (Clickhere).
· A Quickstart guide to Xbee modules first impression (Clickhere).
So back to this post. As I mentioned earlier in this post that I am going to interlink Simulation and practical circuit together.
One circuit is based on DsPIC33FJ256GP710 PIC microcontroller, LCD and Xbee Wireless module and a battery completely separate system or you can say circuit. I made a customized general board designed, two years ago. I named this circuit as DsPIC33Xbee. And second one is based on PIC24 Pic microcontroller, LCD, USB to serial and Xbee RF module. This system is based on simulation but communicating with first system wirelessly through Xbee devices. Both systems will linked up wirelessly. I named this circuit as PIC24Xbee.
In the following figure 1. I have circuit for Simulation. As you have seen that LCD is connected to PortB. And a COMPIM is connected to Uart1 of PIC24. Now this COMPIM is responsible for communicating serially over the physical Serial COM port. Means you can send and receive data externally through this Port quite amazing. Now this COMPIM is connected to my Xbee which is connected to a physical serial port through USB to Serial module.
|Figure 1. Proteus circuit.|
To demonstrate Communication between two circuits I used an example of Conversation between these two circuits. One with a name DsPICXbee and second is PIC24Xbee. In the following figure 2. Animation shows the conversation between these modules. The purpose of doing this is to show how they communicate with each other. This animation is from PIC24Xbee.
|Figure 2. Proteus Simulation.|
In the following figure 3. I have some Practical results from DsPIC33Xbee circuit.
|Figure 3. Practical results.|
In the following figure 4. These are the main functions on left side we have function written for PIC24 and on right side we have function written for DsPIC33F. In both I first initialize LCD then I clear LCD. After that some strings are displayed. Now in while loop DsPIC33 will start the communication by saying “Hi” to PIC24. Now the left sided arrow shows the transmitted message and right sided shows the received message. Now in return to DsPIC “Hi” PIC24 also said “Hi”. You have seen that every sending string has NULL character at the end this is because I want to end the wait for receiving characters with a NULL and want to display it on LCD. After Hi DsPIC33 sends a message “HowAreYou?” because I have limited no. of characters on 20x4 LCD I didn’t use spaces. So in return to this message PIC23 replayed to DsPIC33 “I am Fineeee”. And this goes again and again.
|Figure 4. Main Function.|
So here is the communication between them. As a major application for this post you may use this to interface a remote sensors that communicates with the master control panel placed in your drawing room or control some remote circuits with master control unit.
For having a clear picture of experimental setup please watch this video.
You can download Code (MPLAB X and C30 compiler) and Proteus (v8) Simulation. Click here
Code for both controllers are given.
That’s all for this post hope you will learn please comment if you have any questions for upcoming posts please subscribe or follow.
All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission.
© Copyright 2013 IbrahimLabs. All rights reserved.