Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 10 months ago.
Xbee wireless communication on mbed
i just run a simple code using xbee module on two mbed board, but the receiver cannot get anything, could someone help me solve this problem?
transmitter;
- include "mbed.h"
Serial pc(USBTX, USBRX); Serial xbee1(p9,p10); DigitalOut rst1(p30); Digital reset for the XBee, 200ns for reset DigitalOut myled(LED3);Create variable for Led 3 on the mbed
int main() {
rst1 = 0; Set reset pin to 0 myled = 0;Set LED3 to 0 wait_ms(1);Wait at least one millisecond rst1 = 1;Set reset pin to 1 wait_ms(1);Wait another millisecond
while (1) {Neverending Loop
myled = 1; Turn Led 3 Off int a; a=10; xbee1.printf("%d", a); XBee write whatever the PC is sending xbee1.putc(Y); wait(1); myled = 0; Turn Led 3 on for succcessfull communication wait(1); }
}
receiver;
- include "mbed.h"
Serial xbee1(p9, p10); Serial pc(USBTX, USBRX);
DigitalOut rst1(p30); DigitalOut myled3(LED3); DigitalOut myled2(LED2); DigitalOut myled4(LED4); int main() {
rst1 = 0; Set reset pin to 0 myled2 = 0; myled4=0; wait_ms(1); rst1 = 1; Set reset pin to 1 wait_ms(1); int X;
while (1) { if(xbee1.readable()){ wait(1); xbeel.scanf("%d", &X); myled2 = 1;
xbee1.scanf("%d", &X); X = xbee1.getc(); wait(1); myled2 = 0; if(X==10) {
myled4=1; wait(1);
} else
myled3=1;
} }
}
1 Answer
9 years, 10 months ago.
Please see my example: http://developer.mbed.org/users/ebowles/code/LPC4088_xBee/
I prefer the XBee series 2 and use API mode, which helps with message delivery acknowledgement. When you use the Digi XCTU software, be sure to disable CTS and RTS if these pins are not wired. http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/xctu
Your original code:
#include "mbed.h" Serial pc(USBTX, USBRX); Serial xbee1(p9,p10); DigitalOut rst1(p30); //Digital reset for the XBee, 200ns for reset DigitalOut myled(LED3); //Create variable for Led 3 on the mbed int main() { rst1 = 0; Set reset pin to 0 myled = 0; Set LED3 to 0 wait_ms(1); //Wait at least one millisecond rst1 = 1; Set reset pin to 1 wait_ms(1); //Wait another millisecond while (1) { //Neverending Loop myled = 1; //Turn Led 3 Off int a; a=10; xbee1.printf("%d", a); //XBee write whatever the PC is sending xbee1.putc(Y); wait(1); myled = 0; //Turn Led 3 on for succcessfull communication wait(1); } }
receiver;
# include "mbed.h" Serial xbee1(p9, p10); Serial pc(USBTX, USBRX); DigitalOut rst1(p30); DigitalOut myled3(LED3); DigitalOut myled2(LED2); DigitalOut myled4(LED4); int main() { rst1 = 0; //Set reset pin to 0 myled2 = 0; myled4=0; wait_ms(1); rst1 = 1; //Set reset pin to 1 wait_ms(1); int X; while (1) { if(xbee1.readable()){ wait(1); xbeel.scanf("%d", &X); myled2 = 1; xbee1.scanf("%d", &X); X = xbee1.getc(); wait(1); myled2 = 0; if(X==10) { myled4=1; wait(1); } else myled3=1; } } }