Go Down

Topic: SOLVED !!!! xbee easytransfer library joystick and 2 xbees series 1 (noob) (Read 5477 times) previous topic - next topic

Fabiolus

Good day,

I have been looking everywhere books, etc... I am a novice with xbees.

I am trying to pass analog signal X&Y from pot and  render in arduino then send value to other arduino with xbee SERIE 1 to other Arduino.

This is my second version of sketch to try to accomplish this and now I am to a lost and looking for guidance. I have somewhat success, upon powering up the remote first everything is good, once I power up the power supply one motor only turns slowly but should not, when playing with the joystick I can speed up the motor pressing joystick one way but the other direction does not make the motor go backward.

Thank you very much

Material:
2 xbees series 1
2 dc motors
1 sabertooth driver board
1 joystick
12 volts baterie
9 volts batterie

I have attached the schema for both remote and receiver and below is the sketches for both arduino. Both xbees are reset to default settings

Remote
Code: [Select]
#include <EasyTransfer.h>
EasyTransfer ET;

const int potpin1 = A0;
const int potpin2 = A1;

struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
 Serial.begin(9600);
 //  Serial.begin(115200);
 ET.begin(details(txdata), &Serial);
 // pinMode(potpin1, INPUT);
 // pinMode(potpin2, INPUT);

}

void loop(){

 int val1 = analogRead(potpin1);
 int val2 = analogRead(potpin2);
 val1 = map(val1, 0, 1023, 0, 179);
 val2 = map(val2, 0, 1023, 0, 179);
 txdata.servo1val = val1;
 txdata.servo2val = val2;

 ET.sendData();
}



Receiver
Code: [Select]

#include <Servo.h>
#include <EasyTransfer.h>
EasyTransfer ET;

Servo myservo1;
Servo myservo2;

Servo ST1, ST2;

struct RECEIVE_DATA_STRUCTURE{
 int servo1val;
 int servo2val;
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
 Serial.begin(9600);
 // Serial.begin(115200);

 ET.begin(details(txdata), &Serial);
 // Servo
 ST1.attach( 6, 1000, 2000);
 ST2.attach(5, 1000, 2000);
}

void loop(){
 if(ET.receiveData()){
   ST1.write(txdata.servo1val);
   ST2.write(txdata.servo2val);
   //ST1.write(map(txdata.servo1val, 0, 1023, 0, 180));
   //ST2.write(map(txdata.servo2val, 0, 1023, 0, 180));
 }
}




Fabiolus

Good day,


Finally after many obstacles, faulty wires, wrong code etc... success :smiley-mr-green:.


I present to you communication between 2 arduinos with xbees series 1 with1 joystick passing analog X&Y to other arduino via xbees wireless!!!! All using the EasyTransfer library from Bill Porter http://www.billporter.info/2011/05/30/easytransfer-arduino-library/

This sketch or method can be applied to many different project or other similar controlled bots with minimal coding expertise. I have search and red many books and none come even close to what you are about to see.

I hope you enjoy building your robots and making them controlled wireless.

Pre requisite:

2 xbees series 1 default settings(Out of the box!!) are ok but if you wish you can change the pan id but that is it!!!
1 joystick thumb joystick from ladyaya or equivalent 2 seperate joystick would work.

the way the sketch work you could have a mega arduino and include as much motors/servos/joystick/ button that you wish!!! have fun!!


2 arduino uno board
2 dc motors or servos
9 volts batterie
12/24 volts batterie


http://youtu.be/G-qAB9MzrPU


Please refer to schematic for wiring


Remote control Arduino sketch

Code: [Select]
#include <EasyTransfer.h>
EasyTransfer ET;

const int potpin1 = A0;
const int potpin2 = A1;

struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  //  Serial.begin(115200);
  ET.begin(details(txdata), &Serial);
}

void loop(){

  int val1 = analogRead(potpin1);
  int val2 = analogRead(potpin2);
  val1 = map(val1, 0, 1023, 0, 180);
  val2 = map(val2, 0, 1023, 0, 180);
  txdata.servo1val = val1;
  txdata.servo2val = val2;

  ET.sendData();
}


robot Arduino receiving

Code: [Select]

#include <Servo.h>
#include <EasyTransfer.h>
EasyTransfer ET;

Servo myservo1;
Servo myservo2;

Servo ST1, ST2;

struct RECEIVE_DATA_STRUCTURE{
  int servo1val;
  int servo2val;
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  // Serial.begin(115200);

  ET.begin(details(txdata), &Serial);
  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);
}

void loop(){
  if(ET.receiveData()){
    ST1.write(txdata.servo1val);
    ST2.write(txdata.servo2val);
  }
}




bstott

Thank you for posting your project and results. I just picked up two radios recently and was searching for how to setup. As you realize, the programming is a large hurdle.

Fabiolus

Sweet!

Its not that bad, after playing around with the xbees I realized that the settings would be required only if you wanted to use the xbee itself and program specific pins for your task BUT the method I used needs 2 arduino which is a bit more expensive but leaves you with plenty of options in the end to add more things to your project.

wahwah

You may have exactly what I need here
Please read and let me know what you think??

 New Arduino Uno,
 Apen Hall effect Joystick "X"_"Y" axis 0v-L, 2.5v-Mid,5v-H analog to Arduino UNO
 Sabretooth 60/60

Want to control, Qty 2 DC motors, One from "X" Axis and One from "Y" axis.
 I will be using 2 XBEEs 900mhz for long distance wireless operation between Arduino UNO once I get this working.
 Does anyone have a working sketch that would work for this set up?
Need to control each motor independently, centered position for both "x" and "y" axis would be stopped.
I am presently controlling these motors via same Joystick direct from "x" and "Y" using 5vdc from a Sabertooth 60/60, what I do is rotate Joystick 45 Deg so the "+" pattern is now an "X" pattern and mount it to a console
Now top of pattern "X" both "x" and "y" axis are now max forward speed and bottom of the "X" pattern for both "x" and "y" axis are full reverse
Joystick moved straight forward both motors drive forward, Joystick pulled straight back both motors drive straight reverse, any variation left or right steers unit in that direction
I have never tried this programing other than trying to find a program already written and uploading to Arduino, no luck yet, I have the XBEE`s talking with each other, but need coding for both Arduino`s transmit and receive ends
Willing to pay for some help if needed
  Please advise, Thank You

jimkan

@Fabiolus, what xbee mode are you running on? router/router or corrdinator/router, AT or API mode?

Thanks,

MarcoTheFenix

I had a similar problem, reading the comments I have an idea that could be the problem :)

Go Up