Good day,
I wanted to share my project, I am stuck in what is for me a big wall at the moment for me, I have tried different approaches and fail and wanted to see if a different approach should be taken in consideration or if what I am trying to achieve is feasible.
Basically trying to pass analog signal X&Y from a joystick from xbee to xbee and then render it in Arduino. I have tried to include the analog signal of the Y axe and I fail all the time.
Any assistance would be appreciated in completing this project which I would like to share once done.
Thank You
My settings:
Transmitter xbee series 1 settings
ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR
Receiver xbee series 1 settings:
ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR
where I am at so far
sketch found in the Arduino receiver (no sketch needed in the transmitter Arduino)
/*
XBeeAnalogReceiveSeries1
Read an analog value from an XBee API frame and set the value accordingly.
*/
#include <Servo.h>
int servoVal;
int servoVal2;
Servo ST1, ST2;
void setup() {
// Servo
ST1.attach( 6, 1000, 2000);
ST2.attach(5, 1000, 2000);
Serial.begin(9600);
configureRadio(); // check the return value if you need error handling
}
boolean configureRadio() {
// put the radio in command mode:
Serial.flush();
Serial.print("+++");
delay(100);
String ok_response = "OK\r"; // the response we expect.
// Read the text of the response into the response variable
String response = String("");
while (response.length() < ok_response.length()) {
if (Serial.available() > 0) {
response += (char) Serial.read();
}
}
// If we got the right response, configure the radio and return true.
if (response.equals(ok_response)) {
Serial.print("ATAP1\r"); // Enter API mode
delay(100);
Serial.print("ATCN\r"); // back to data mode
return true;
}
else {
return false; // This indicates the response was incorrect.
}
}
void loop() {
if (Serial.available() >= 14) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 10; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();
int analogValue = analogLow + (analogHigh * 256);
servoVal = map(analogValue, 0, 1023, 0, 180); // scale it to use it with the servo (result between 0 and 180)
ST1.write(servoVal); // sets the servo position according to the scaled value
}
}
}