Arduino to Arduino Xbee Communication
Moderators: adafruit_support_bill, adafruit

Arduino to Arduino Xbee Communication

by Aluman000 on Sat Nov 10, 2012 11:05 am

I am having a downright pickle of a time trying to get my arduinos to talk to each other.
I am trying to control a remote controlled car with a PS2 controller, wirelessly.
I have 2 Arduinos connected to 2 Xbees.

The sending station has the following code:
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
#include <PS2X_lib.h>  //for v1.6


SoftwareSerial Xbee(2, 3); // RX on pin 2 (unused), TX on pin 3 (to Xbee).
PS2X ps2x; // create PS2 Controller Class

int LMotor;
int RMotor;

void setup()
{
  Xbee.begin(57600);
  Serial.begin(57600);
  ps2x.config_gamepad(7,11,10,12, true, true);

} // Setup

void loop()
{
  ps2x.read_gamepad(false, 1);
  LMotor = (ps2x.Analog(PSS_LY)-127)*-1*(50)/127 + 64;
  RMotor = (ps2x.Analog(PSS_RY)-127)*-1*(50)/127 + 64;
 
 
  Serial.print(LMotor); 
  Xbee.print(LMotor);
 
  Serial.print(" - ");

  Serial.println(RMotor);
  Xbee.print(RMotor);

} // Loop


I have connected the receiving Xbee to Hyperterm and the data comes through, no problem.

I have played with about 100 different ways to set up the receiving Arduino. *None* work.
I have tried:
1. using print and write functions from the sending station.
Amazingly, I can get write to work... For every other character.
2. trying to parse the incoming data while looking for '10' or '/r' or basically any kind of method to signal the end of a number and they never work.

Here's What Hyperterm sees when the controller is at rest:
Code: Select all | TOGGLE FULL SIZE
61
67
61
67
61
67
61
67
61
67
61
67
61
67
61
67
61
67
61
67
61


Here's what my Uno Returns:
Code: Select all | TOGGLE FULL SIZE
54
183
134
133
54
145
134
133
54
183
134
133
54
145
134
133
54
151
134
133
54
177
134
133
54
183
134
133
54


With this code:
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

SoftwareSerial Xbee(2,3);

int LMotor;
void setup()
{
  Serial.begin(57600);
  Xbee.begin(57600); 
} // Setup

void loop()
{
  delay(1000);
   
  if(Xbee.available())
  {
   
    LMotor = Xbee.read();
   Serial.println(LMotor);
   
  }
 
} // Loop


Thanks for any help.
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 3:27 pm

Re: Arduino to Arduino Xbee Communication

by Zener on Sun Nov 11, 2012 3:52 pm

I am a little unclear on what you are doing but I will give a couple of ideas. If you have a scope or logic analyzer take a look at the serial stream and maybe that will give you some ideas. Otherwise, I would verify your baud rates and maybe try some different ones. Also, make sure the serial line is not inverted. Sometimes a MAX232 or other inverter is needed. Good luck.
Zener
 
Posts: 2540
Joined: Sat Feb 21, 2009 1:38 am

Re: Arduino to Arduino Xbee Communication

by Aluman000 on Mon Nov 12, 2012 10:54 am

Yes, it is difficult to convey the whole system.
But the tough part for me is :
1. the Sending Arduino can create the message
2. the Sending Xbee transmits it
3. the receiving Xbee receives it fine
4. Hyperterm accepts the info coming out of the Xbee fine
but
5. The Receiving Arduino can't seem to understand what's coming out of the Xbee.

Do either of those suggestions address this problem?
I'm certain the Baud Rate isn't the problem.
Would hyperterm be ok if the serial line was inverted?

thanks regardless!
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 3:27 pm

Re: Arduino to Arduino Xbee Communication

by Zener on Mon Nov 12, 2012 8:24 pm

What if you hook the transmitting Arduino directly to receiving Arduino? Does it work then? I would try that.

I had a similar problem before, and the guy I was working with assured me it was not a problem with the baud rate. In the end it was a problem with the baud rate. One of the config bits was set wrong. This was on a Microchip part however, but it can happen to any processor.
Zener
 
Posts: 2540
Joined: Sat Feb 21, 2009 1:38 am

Re: Arduino to Arduino Xbee Communication

by Aluman000 on Wed Nov 14, 2012 2:31 pm

Ok That's a great idea. Much simpler.
So I connected 1 Uno to the Other and... Same Problem.
I just don't seem to be able to receive Serial from another Arduino.

It's really simple now.
I connect the tx pin on the Uno sending an integer using Software Serial .print() command to a second Uno's rx pin using Software Serial .read() command, and the values just get lost...

This time I get this:
Code: Select all | TOGGLE FULL SIZE
54
53
255
183
183
247
51
54
54
255
255
183
183
247
54
52
255
219
255
243
255
255
54
55
183
251
255
255
251
255
255
55
183
187
223
255
255
255
255
183
187
183
255
255
Aluman000
 
Posts: 27
Joined: Sun Apr 10, 2011 3:27 pm