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
#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
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
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
#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.

