Xbee Communication

Hi everybody, i have some questions about Xbee communication, i have to send a program which put HIGH on a LED with a xbee, and receive and execute this program with another xbee, my question is :

I don't want to set both xbee, just want to try to send something with a line of code, i saw exemple with " Serial.println() " and " Serial.read() ", is it the best choice to communicate and send programs?

If someone can help me giving me a little exemple of a program to send something to the xbee and to read it, i take!

i have to send a program which put HIGH on a LED with a xbee, and receive and execute this program with another xbee,

You can send and execute a program using XBees. You can send messages using XBees, and have the Arduino(s) understand the that message means turn the LED on or off.

is it the best choice to communicate and send programs?

It's best, because it's the only choice.

If someone can help me giving me a little exemple of a program to send something to the xbee and to read it, i take!

Forget the XBees, for a while. Make one Arduino send a message to the Serial Monitor application. Make the other Arduino receive a message from the Serial Monitor application, and react appropriately.

Then, install the XBee shields and XBees (after properly configuring them) and the same sketches on the the Arduinos will work.

PaulS:

i have to send a program which put HIGH on a LED with a xbee, and receive and execute this program with another xbee,

You can send and execute a program using XBees. You can send messages using XBees, and have the Arduino(s) understand the that message means turn the LED on or off.

is it the best choice to communicate and send programs?

It's best, because it's the only choice.

If someone can help me giving me a little exemple of a program to send something to the xbee and to read it, i take!

Forget the XBees, for a while. Make one Arduino send a message to the Serial Monitor application. Make the other Arduino receive a message from the Serial Monitor application, and react appropriately.

Then, install the XBee shields and XBees (after properly configuring them) and the same sketches on the the Arduinos will work.

Hello, thanks to reply me, the matter is that my teacher told us " you don't have to configure xbee to communicate, they already do this " .. and i saw a program from an arduino book which send letters in serial monitor and increase / decrease brightness from a led with a potentiometer with 2 xbee but the program is too advenced.. the program use Serial.println() and Serial.read() and i think that it is the command to communicate with xbee without configure them.

So if i understand you, in the serial monitor i can send message to another xbee and he can understand that message, exemple if i send to serial monitor " analogWrite(3, HIGH); ", he will put +5v to the 3 pin .. i'll follow what you should me ! Thank you

If someone has another explication for me, give me please.

the matter is that my teacher told us " you don't have to configure xbee to communicate, they already do this "

And, of course, he's never once in his life been wrong.

and i saw a program from an arduino book which send letters in serial monitor and increase / decrease brightness from a led with a potentiometer with 2 xbee but the program is too advenced.

Then you better get studying. There is nothing "too advanced" about sending and receiving letters.

So if i understand you, in the serial monitor i can send message to another xbee and he can understand that message, exemple if i send to serial monitor " analogWrite(3, HIGH); ", he will put +5v to the 3 pin

You can send that message. But, then you need to write the code to read, store, parse and understand that message. The Arduino won't automatically understand it.

Jeffdecod:
So if i understand you, in the serial monitor i can send message to another xbee and he can understand that message, exemple if i send to serial monitor " analogWrite(3, HIGH); ", he will put +5v to the 3 pin

No. The Arduino receiving the message has to parse the character stream coming through the Xbee and then act appropriately. Sending an actual Arduino function call within a string will not automatically call that function. You are just sending bytes over the Xbees, that is it.

You know a good way to learn this is to Google "xbee arduino tutorial". There are many to choose from to help you understand this.

Another good place to look is chapter 14 of the book "Arduino Cookbook". Great explanations and good sample code.

PaulS:

the matter is that my teacher told us " you don't have to configure xbee to communicate, they already do this "

And, of course, he's never once in his life been wrong.

and i saw a program from an arduino book which send letters in serial monitor and increase / decrease brightness from a led with a potentiometer with 2 xbee but the program is too advenced.

Then you better get studying. There is nothing "too advanced" about sending and receiving letters.

So if i understand you, in the serial monitor i can send message to another xbee and he can understand that message, exemple if i send to serial monitor " analogWrite(3, HIGH); ", he will put +5v to the 3 pin

You can send that message. But, then you need to write the code to read, store, parse and understand that message. The Arduino won't automatically understand it.

Thanks to all to reply me, ok i'll check books on xbee :slight_smile:

Xbee can communicate without be configured this program works :wink:

To send

// constants won't change. They're used here to 
 2 // set pin numbers:
 3 const int buttonPin = 12;    // the number of the pushbutton pin
 4 const int ledPin =  13;      // the number of the LED pin
 5 
 6 // variables will change:
 7 int buttonState = 0;         // variable for reading the pushbutton status
 8 
 9 void setup() {
10   // initialize serial communication (since we are using Xbee):
11   Serial.begin(9600);
12   // initialize the LED pin as an output:
13   pinMode(ledPin, OUTPUT);      
14   // initialize the pushbutton pin as an input:
15   pinMode(buttonPin, INPUT);     
16 }
17 
18 void loop(){
19   // read the state of the pushbutton value:
20   buttonState = digitalRead(buttonPin);
21 
22   // check if the pushbutton is pressed.
23   // if it is, the buttonState is HIGH:
24   if (buttonState == HIGH) {     
25     // turn LED on:    
26     digitalWrite(ledPin, HIGH);
27     //Send H char using Xbee module
28     Serial.print('H');
29   } 
30   else {
31     // turn LED off:
32     digitalWrite(ledPin, LOW);
33     //Send L char using Xbee module
34     Serial.print('L');
35   }
36 }

To read :

void loop() {
 2   // see if there's incoming serial data:
 3   if (Serial.available() > 0) {
 4     // read the oldest byte in the serial buffer:
 5     incomingByte = Serial.read();
 6     // if it's a capital H (ASCII 72), turn on the LED:
 7     if (incomingByte == 'H') {
 8       digitalWrite(ledPin, HIGH);
 9     } 
10     // if it's an L (ASCII 76) turn off the LED:
11     if (incomingByte == 'L') {
12       digitalWrite(ledPin, LOW);
13     }
14   }
15 }

Thanks i succed, my teacher was good :wink:

It's still worth seeing what the configuration of the XBees is. I'm guessing that the configuration is such that each is broadcasting to every other node on the network, which is not only insecure, it is much slower that directed communications. While it might not matter in a simple on/off situation, try wiring a potentiometer to one of the Arduinos and sending that value to the other to adjust the PWM value of an LED, and I suspect that the lag will be quite noticeable.