Use RC Remote for Flight Simulator with Arduino

Posted by admin on Samstag 23 Januar 2016

Since I was not able to use the serial cable of my FlySky FS-CT6B with my Mac, I’ve searched for an alternative to use my remote with flight simulators.

With the help of UnoJoy I was able to use my Arduino Uno (Rev 3) as a joystick input. The Arduino library EnableInterrupt is very handy for interrupt handling, which is needed to decode the PWM signals provided by the RC receiver.

Here my setup:

  1. Connect GND of Arduino with the (-) pin in the Bat row of the receiver
  2. Connect 5V of Arduino with the (+) pin in the Bat row of the receiver
  3. Connect each data pin of the receiver channels with an Arduino channel. E.g CH1 to Arduino 2, CH2 to 3, …
  4. Upload the source code below to your Arduino
  5. Follow the instructions from UnoJoy to turn your Arduino in a joystick
  6. Start you favorite flight simulator like HeliX
  7. Enjoy!

#define EI_ARDUINO_INTERRUPTED_PIN
#include 
#include "UnoJoy.h"

static const int Channels = 6; // 0 - 5
static int ChannelsToPin[Channels] = {2, 3, 4, 5, 6, 7};
static int PinToChannels[8] = {0, 0, 0, 1, 2, 3, 4, 5};
volatile int PwmValue[Channels] = {0};
volatile int PrevTime[Channels] = {0};

void rising()
{
  const int Pin = arduinoInterruptedPin;
  PrevTime[PinToChannels[Pin]] = micros();
  enableInterrupt(Pin, falling, FALLING);
}

void falling() {
  const int Pin = arduinoInterruptedPin;
  const int Channel = PinToChannels[Pin];
  PwmValue[Channel] = micros()-PrevTime[Channel];
  enableInterrupt(Pin, rising, RISING);
}

void setup() {
 for(int i = 0; i < Channels; ++i) {
  pinMode(ChannelsToPin[i], INPUT_PULLUP);
  enableInterrupt(ChannelsToPin[i], &rising, RISING);
 }
 setupUnoJoy();
}

void loop() {
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);
}

dataForController_t getControllerData(){
  dataForController_t controllerData = getBlankDataForController();
  controllerData.leftStickX = crop8(map(PwmValue[2]-1500, -450, 450, 0, 255));
  controllerData.leftStickY = crop8(map(PwmValue[3]-1500, -450, 450, 0, 255));
  controllerData.rightStickX = crop8(map(PwmValue[1]-1500, -450, 450, 0, 255));
  controllerData.rightStickY = crop8(map(PwmValue[0]-1500, -450, 450, 0, 255));
  return controllerData;
}

uint8_t crop8(int val) {
  return min(255, max(0, val));
}
Posted in Arduino  Comment

Leave a Reply

Spam protection by WP Captcha-Free