Go Down

Topic: Simple ESC control over XBEE using EasyTransfer (Read 786 times) previous topic - next topic

octobersky

Apr 04, 2015, 12:32 pm Last Edit: Apr 04, 2015, 12:58 pm by octobersky Reason: Post code
Hi, I'm still only new to Arduino (2 years) and still learning. Just thought I would share some code I've been utilising to control my RC car with the V2 Gamepad but this code will work with any 2 thumb sticks connected to an Arduino. My reason for posting is due to the trouble I had working out simple analog control of an ESC over XBEE, after hours googling I finally worked out EasyTransfer was the easiest way to do it. Thanks to Bill Porter who compiled a library allowing us to make easy calls to utilise different functions over XBEE.

Here is my TX and RX code:

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

int potpin1 = A4;
int potpin2 = A3;

struct SEND_DATA_STRUCTURE{
  int servo1val;
  int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
  Serial1.begin(57600);
  ET.begin(details(txdata), &Serial1);
}

void loop(){
  txdata.servo1val = analogRead(potpin1);
  txdata.servo2val = analogRead(potpin2);

   
  ET.sendData();
  delay(10);
}


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

Servo myservo1;
Servo myservo2;


struct RECEIVE_DATA_STRUCTURE{
  int servo1val;
  int servo2val;

 
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
  Serial1.begin(57600);
  myservo1.attach(3);
  myservo2.attach(5);
  ET.begin(details(txdata), &Serial1);
}

void loop(){
  if(ET.receiveData()){
   
    myservo1.write(map(txdata.servo1val, 0, 1023, 0, 179));
    myservo2.write(map(txdata.servo2val, 0, 1023, 179, 0));   
  }
}

Go Up