Xbee point to point help

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tinkeringtech
 
Posts: 98
Joined: Wed Nov 23, 2011 10:08 pm

Xbee point to point help

Post by tinkeringtech »

Hi, I have been trying to set up a point-point connection following the instructions at http://www.ladyada.net/make/xbee/point2point.html

My hardware is
Sensor-->Arduino --> Xbee Xbee-->Arduino-->PC(Serial monitor)

An issue I'm having with the tutorial is that it uses an FTDI cable on the receving side. I want to connect the receiving Xbee to an Arduino. I know that I can connect the sensor directly to the ADC pins on the transmitting Xbee, but I want the Arduino also on the transmit side.
The code below basically serial prints "test" over and over.
I want that word to be seen in the serial monitor that is connected to the Arduino on the receiving side. I'm confused on what code to use here. This problem may seem trivial, but I'm really confused. Plus, the p-p tutorial talks about replicating what is being typed into the serial monitor. I don't need that capability. Any help would be appreciated.

I tried this code, but no success. I have the TX/RX pins of the Xbees connected to the TX/RX pins of the Arduino on either end.

Sketch in Transmit Arduino

Code: Select all

void setup() {
Serial.begin(9600);
}
void loop() {
char data = 'test';
Serial.print(data); //print value to xbee (serial port)
delay(100); // stop the program for some time
Sketch in Receving Arduino

Code: Select all

void setup() {
Serial.begin (9600);
}
void loop() {
  while(Serial.available())
  { 
char getData = Serial.read();
Serial.print (getData);
  }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Xbee point to point help

Post by adafruit_support_rick »

On the receiving side, you are receiving the test message, and then writing it back to the xbee instead of sending it to the serial monitor.

You need two different serial ports on the receiver - one to listen to the Xbee, and one to write to the serial monitor.

The simplest thing would be to use SoftwareSerial to listen to the xbee. You will have to connect the xbee to a different pair of pins, and then initialize the software serial object to use those pins.

SoftwareSerial is a standard Arduino Library component.

User avatar
tinkeringtech
 
Posts: 98
Joined: Wed Nov 23, 2011 10:08 pm

Re: Xbee point to point help

Post by tinkeringtech »

driverblock wrote:On the receiving side, you are receiving the test message, and then writing it back to the xbee instead of sending it to the serial monitor.

You need two different serial ports on the receiver - one to listen to the Xbee, and one to write to the serial monitor.

The simplest thing would be to use SoftwareSerial to listen to the xbee. You will have to connect the xbee to a different pair of pins, and then initialize the software serial object to use those pins.

SoftwareSerial is a standard Arduino Library component.
Do you mean something like the code below on the receiving side? Have the receiving xbee tx/rx connected to pins 4,5 instead on the receiving arduino? Thanks for your help...

Code: Select all

#include <NewSoftSerial.h>
NewSoftSerial xbeeSerial(4, 5);

void setup() {
Serial.begin (9600);
xbeeSerial.begin(9600);
}
void loop() {
  while(xbeeSerial.available())
  { 
char getData = xbeeSerial.read();
Serial.print (getData);
  }
}

User avatar
faludi
 
Posts: 25
Joined: Thu Jul 17, 2008 3:58 pm

Re: Xbee point to point help

Post by faludi »

That looks like a good solution, one that avoids sending information back to the XBee in a loop. Did it work for you?

User avatar
tinkeringtech
 
Posts: 98
Joined: Wed Nov 23, 2011 10:08 pm

Re: Xbee point to point help

Post by tinkeringtech »

[img]Sorry for the delay in replying.
Yes, it worked. Below is the code for the TX and RX Xbees. I have the Analog0 values from the TX Xbee being reported to the RX Xbee. A question I had was, do I have to use data type "char" on the receiving Xbee? It seems that when I have A0 connected to 5V on the TX Xbee, I get the following:
1
0
2
3
1
0
2
3

..and so on. Do the Xbee transmit 1 char at a time? would I need some sort of an array to store each char and read back? Feel like I'm missing something fundamental to the function of Xbees...BTW, both adapter boards were assembled like the receiver Xbee on the Tweet-a-watt design. Thanks!

Code: Select all

//TX XBEE

#include <NewSoftSerial.h>
NewSoftSerial xbeeSerial(4, 5);
int analogPin = 0; 

void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
int analogval = analogRead(analogPin); 
xbeeSerial.print(analogval);
delay(100); // stop the program for some time
}

//RX XBEE

#include <NewSoftSerial.h>
NewSoftSerial xbeeSerial(4, 5);

void setup() {
Serial.begin (9600);
xbeeSerial.begin(9600);
}
void loop() {
  while(xbeeSerial.available())
  { 
char getData = xbeeSerial.read();
Serial.print (getData);
Serial.print ("\n");
  }
}
Attachments
IMAG0686.jpg
IMAG0686.jpg (255.32 KiB) Viewed 1719 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Xbee point to point help

Post by adafruit_support_rick »

The XBees transmit one character at a time, just like a regular serial port.
Maybe the easiest thing for you to do to get your data to print out the way you want it is to use println() on the transmitter:

Code: Select all

xbeeSerial.println(analogval);
and take out the print ("\n") on the receiver.

Code: Select all

  while(xbeeSerial.available())
  { 
char getData = xbeeSerial.read();
Serial.print (getData);
  }
That way, the carriage return will be transmitted at the end of your analog value, and automatically printed by the receiver.

User avatar
tinkeringtech
 
Posts: 98
Joined: Wed Nov 23, 2011 10:08 pm

Re: Xbee point to point help

Post by tinkeringtech »

Thanks for all your help. It works fine now....One other note for documentation sake. The Xbees have default configurations except for the MY value on the TX side is "1".
Vals coming from the TX Xbee
GND pin
0
0
0

5V pin
1023
1023
1023

3.3V pin
710
710
710

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”