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.
11 years, 7 months ago.
confused about xbee mbed rx code
hey ppl.. i need to write a code where one xbee+mbed is trasmitting a particular character (say "A") and the other mbed+xbee is receiver and if it receives "A" then any one of the Led shld glow
i tried writing the code of tx.. but confused abt the RX code
TX code
#include "mbed.h"
Serial xbee1(p9, p10);
DigitalOut rst1(p11);
DigitalOut myled(LED3);
DigitalOut myled2(LED4);
Serial pc(USBTX, USBRX);
int main() {
rst1 = 0; //Set reset pin to 0
myled = 0;//Set LED3 to 0
myled2= 0;//Set LED4 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
if (pc.readable()) {//Checking for serial comminication
myled = 0; //Turn Led 3 Off
xbee1.printf("A"); //XBee writes "A"
myled = 1; //Turn Led 3 on for succcessfull communication
}
}
}
RX code
#include "mbed.h"
Serial xbee1(p9, p10);
DigitalOut rst1(p8);
DigitalOut myled(LED1);
DigitalOut myled2(LED2);
//TextLCD lcd(p15, p16, p17, p18, p19, p20);
int main() {
rst1 = 0; //Set reset pin to 0
myled = 0;
myled2=0;
wait_ms(1);
rst1 = 1; //Set reset pin to 1
wait_ms(1);
char X;
while (1) {
if(xbee1.readable()){
wait(1);
myled = 1;
xbee1.scanf("%c", &X);
// X = xbee1.getc();
wait(1);
myled = 0;
if(X=='A')
myled2=1;
}
}
}
is the code correct for RX??
3 Answers
11 years, 7 months ago.
You could try this; The RTC time is sent from one Mbed to another every 5 seconds.
You can remove oled code and use the TextLCD code instead, I have tried on both.
My Xbee's are on p13 and p14
Xbee RTC TX code
#include "mbed.h"
#include "TextLCD.h"
#include "OLED32028P1T.h"
OLED32028P1T oled(p28, p27, p29); // Oled Display tx, rx, rs
//TextLCD lcd(p12, p21, p11, p8, p7, p6, p5); // rs, rw, e, d4, d5, d6, d7
DigitalOut myled(LED1);
Serial xbee(p13,p14); // tx, rx
Ticker t;
void send(){
myled=1;
time_t seconds = time(NULL);
xbee.printf("%d",seconds);
myled=0;
}
int main() {
oled.init();oled.clear();oled.setTextBackgroundType(TEXT_OPAQUE);
oled.setFontColor(oled.toRGB(255,255,255));oled.setFontSize(FONT8X12);
//lcd.cls()
oled.printf("Send Time every\n");
//lcd.printf("Send Time every\n");
oled.printf("5 Seconds ");
//lcd.printf("5 Seconds ");
wait(2);
t.attach(&send, 5);
while (1) {
time_t seconds = time(NULL);
char buffer[40];
oled.locate(0,0);
//lcd.locate(0,0);
strftime(buffer, 40, "%I:%M:%S %p\n", localtime(&seconds));
oled.printf("Time %s",buffer);
//lcd.printf("Time %s\n",buffer);
strftime(buffer, 40, "%a %d %b %Y", localtime(&seconds));
oled.printf("Date %s",buffer);
//lcd.printf("Date %s",buffer);
}
}
Xbee RTC RX code
#include "mbed.h"
#include "TextLCD.h"
#include "OLED32028P1T.h"
//TextLCD lcd(p12, p24, p24, p30, p22, p23, p11); // rs, rw, e, d4, d5, d6, d7
OLED32028P1T oled(p28, p27, p29); // Oled Display tx, rx, rs
Serial xbee1(p13, p14);
DigitalOut led1(LED1);
DigitalOut led4(LED4);
struct tm t;
int x;
int count;
char data_buf[10];
int main() {
oled.init();oled.clear();oled.setTextBackgroundType(TEXT_OPAQUE);
oled.setFontColor(oled.toRGB(255,255,255));oled.setFontSize(FONT8X12);
//lcd.cls();
wait_ms(10);
while(1){
oled.locate(0,0);
//lcd.locate(0,0);
time_t seconds = time(NULL);
char buffer[40];
strftime(buffer, 40, "%I:%M:%S %p", localtime(&seconds));
oled.printf("Time %s\n",buffer);
//lcd.printf("Time %s\n",buffer);
strftime(buffer, 40, "%a %d %b %Y", localtime(&seconds));
oled.printf("Date %s",buffer);
//lcd.printf("Date %s",buffer);
if(xbee1.readable()) {
led1 = 1;count=0;
while (count < 10 ) {
data_buf[count] = xbee1.getc();
count++;
}
x = atol(data_buf);
set_time(x+1); led4 = 1; // add 1 second for tx/rx delay
led1 = 0;
}
}
}
11 years, 7 months ago.
The mbed board has led so i wish that one of the led shuld glow...and hence i wrote the program (led 3) isit not possible??
11 years, 7 months ago.
Are your Xbees configured properly? Are they using the same PAN ID? Is the Node Identifier correct? Can you check these values with the X-CTU tool?