View previous topic :: View next topic |
Author |
Message |
fazreen
Joined: 18 Oct 2012 Posts: 10
|
communicate PIC to PIC from tx to rx in xbee |
Posted: Wed Oct 24, 2012 9:39 pm |
|
|
Someone can help me how to communicate PIC TO PIC by xbee ? I had done communicate pic to pic from tx to rx using wire. But now I want communicate without use wire but use xbee. What's the program that I can use it ? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: communicate PIC to PIC from tx to rx in xbee |
Posted: Thu Oct 25, 2012 1:55 am |
|
|
fazreen wrote: | Someone can help me how to communicate PIC TO PIC by xbee ? I had done communicate pic to pic from tx to rx using wire. But now I want communicate without use wire but use xbee. What's the program that I can use it ? |
It depends. If you are using something like an XBeePro then these have two modes of operation, one where you use them as a point-to-point link and the other where you have a one-to-many or many-to-many type of operation. If you are using them for point-to-point then you just use the XBeePro as if it were a piece of wire.
To set the mode of the device you can you the standard tool provided by the company that makes the XBeePro (forgotten the name of the app) or you can sent it "at" style commands. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Oct 25, 2012 9:07 am |
|
|
You might want to get a copy of the book "Building Wireless Sensor Networks" by Robert Faludi - it was the only decent source of information out there that I found when I was looking for it (I am including a ZigBee link in my hummingbird feeder heater ... that I really need to get finished - we are starting to see frost around here!). Lots of good info in that book on how to use them and get them to talk together. _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
fazreen
Joined: 18 Oct 2012 Posts: 10
|
this program can use for pic to pic by using two xbee ? |
Posted: Sun Nov 04, 2012 5:54 am |
|
|
This program can use for comunicate pic to pic by using two xbee ? and it is use uart protocol ?
Transmitter
Code: |
/* pic2pic_transmit.c
ME333 Lab 5
The transmitter checks to see if PIN A0 is high or low.
If the pin is high, the transmitter sends the signal 'a' to the receiver and
turns on an LED. If the pins is low, the transmitter sends the signal 'b'.
*/
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000) // 20 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1) // you can use any pins for software uart...
#use rs232(baud=9600, UART1) // hardware uart much better; uses RC6/TX and RC7/RX
// characters tranmitted faster than the pic eats them will cause UART to hang.
#include <stdlib.h>
#define LED_0 PIN_D0
void main() {
while (TRUE) {
if (input(PIN_A0)){
output_high(LED_0);
printf("a"); //sends signal a
}
else{
output_low(LED_0);
printf("b"); //sends signal b
}
}
}
|
Receiver
Code: |
/* pic2pic_receive
ME 333 Lab 5
The receiver checks the signal from the XBEE and if the signal is 'a', the receiver turns on an LED.
*/
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000) // 20 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1) // you can use any pins for software uart...
#use rs232(baud=9600, UART1) // hardware uart much better; uses RC6/TX and RC7/RX
// characters tranmitted faster than the pic eats them will cause UART to hang.
#define LED_0 PIN_D0
#include <stdlib.h>
char x;
void main() {
while (TRUE) {
if (kbhit()) {
x = getc();
}
if (x=='a'){
output_high(LED_0);
}
else{
output_low(LED_0);
}
}
} |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Nov 05, 2012 5:42 pm |
|
|
In the program from your other (closed) thread, change the to
Also, when posting code in the forum please use the 'code' buttons. You do know how this works. It makes your code much easier to read and will get you quicker and better answers.
And, please be correct in writing comments: Code: | #use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors ) // 4 MHZ CRYSTAL | 4MHz or 20MHz ????
and also: Code: | //set_tris_c(0x80); // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000) | Port c or port d??? And not all pins are output, pin 7 is input.
You have more errors like this. Better not to write comments then to write bad comments. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Nov 05, 2012 7:59 pm |
|
|
One suggestion I came across some time ago that I have been trying to follow to avoid the "if(data='b') " error is to write it reversed. Write the code as "if('b'==data)" -- that way when you forget the double == and use a single one, the compiler throws it out instead of quietly assigning the letter b to data (which is always true). Saved me a few times now
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|