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:
- Connect GND of Arduino with the (-) pin in the Bat row of the receiver
- Connect 5V of Arduino with the (+) pin in the Bat row of the receiver
- Connect each data pin of the receiver channels with an Arduino channel. E.g CH1 to Arduino 2, CH2 to 3, …
- Upload the source code below to your Arduino
- Follow the instructions from UnoJoy to turn your Arduino in a joystick
- Start you favorite flight simulator like HeliX
- 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));
}
Mittwoch 2 August 2017 08:04
… [Trackback]…
[...] Informations on that Topic: brainos.bplaced.net/2016/01/use-rc-remote-for-flight-simulator-with-arduino/ [...]…
Montag 22 Januar 2018 23:41
Hello, is 3 days that i’m trying to use my FS-i6 radio with my reciever FS-IA6 connected to Arduino UNO REV3. I already used UnoJoy for some homemade controllers, but with this project i cannot find a solution.
I uploaded on arduino, both this code and the updated one on Dropbox, connected everything, used the unojoy script to convert the arduino in joystic…. but no results, the only thing i have is mixed signals in the “controller proprieties” inside windows, or no movement at all.
In serial port from your sketch from dropbox i see the values changing, but when i use the script from unojoy to convert it to joystic, nothing happen and the joystick proprieties dosent show movement…
PLEASE HELP ME!