R/C to USB Bridge

by georational in Circuits > USB

1803 Views, 2 Favorites, 0 Comments

R/C to USB Bridge

_-3.JPG

Converts PPM signals from a radio receiver into joystick positions

Use it to play your favorite games and flight simulators with your R/C radio transmitter. This Instructable uses an Arduino from littleBits and a DSMX receiver plus a simple code snippet to make this conversion.

You will need

  • Power
  • Arduino
  • USB cables
  • pin headers
  • jumper wire
  • a radio receiver with PPM output.

Solder Pin Headers to the Arduino's Additional I/O Ports

ArduinoBit--additionalPins.png

In order to power the receiver (RX), pin headers need to be added to the Arduino. This will also make the wiring between the Bit and the RX a lot easier.
See http://discuss.littlebits.cc/t/using-the-additional-i-os-on-the-arduino-bit for more information.

Add the Arduino Joystick Library to Your IDE

arduino-ide-lib-before.png

You can find the library on GitHub, https://github.com/MHeironimus/ArduinoJoystickLib... Thank you, Matthew Heironimus, for writing it.

Only certain Arduinos can emulate a HID like a joystick. As the littleBits microcontroller is an Arduino Leonardo at heart you are good to go.

Flash the Code Onto the Arduino

#include <Joystick.h>

#define inputPin 16
#define channels 4
#define lo 800 //adjust to output of RX
#define hi 1600 //adjust to output of RX
#define filter 10

int channel[channels];
int previousValue[channels];
int counter = 0;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_MULTI_AXIS, 0, 0,
true, true, false, false, false, false,
true, true, false, false, false);



void setup()
{
Joystick.setXAxisRange(lo, hi);
Joystick.setYAxisRange(lo, hi);
Joystick.setThrottleRange(lo, hi);
Joystick.setRudderRange(lo, hi);

Joystick.begin();
Serial.begin(9600);
pinMode(inputPin, INPUT);
}



void loop()
{

if(pulseIn(inputPin, HIGH) > 3000)
{
for(int i = 0; i <= channels-1; i++)
{
channel[i]=pulseIn(inputPin, HIGH);
}
for(int i = 0; i <= channels-1; i++)
{
if((channel[i] > 2000) || (channel[i] <500))
{
channel[i] = previousValue[i];
}
else
{
channel[i] = (previousValue[i]+channel[i])/2;
counter++;
}
}
Joystick.setXAxis(channel[0]);
Joystick.setYAxis(channel[1]);
Joystick.setThrottle(channel[2]);
Joystick.setRudder(channel[3]);
}

if(counter > filter)
{
for(int i = 0; i <= channels-1; i++)
{
Serial.print("channel ");
Serial.print(i+1);
Serial.print(": ");
Serial.println(channel[i]);
previousValue[i]=channel[i];
}
counter=0;
}
}

Please be aware that the code which bridges between the R/C signal and the emulated USB HID comes in its simplest form. The function used here – pulseIn – is a blocking function. Read here, and here, how to implement a non-blocking approach using interrupts.

Downloads

Do the Wiring

_-2.JPG
_.JPG

Connect jumper wire / DuPont cables between the Bit and the RX. The connectors at the end of these cables need to be female. We connect GND (blue), VCC (brown) and signal (orange) from the PPM port of the RX to GND, VCC and d16 on the Arduino.

Bind the Receiver

Disconnect the Arduino from power. Put the binding harness into the connector location marked BIND on the RX. Turn on your radio transmitter and switch it into bind mode. Next apply power to the Arduino. The bind process was successful when the LED in the receiver turns on.

Adjust the Code to Your Circumstances

The constants hi and lo in the Arduino sketch need to be altered to reflect the actual output of the receiver you are using.

#define lo 800
#define hi 1600

The signals inside the PPM pulse ideally range from 1000μs to 2000μs. The RX used in this Instructable outputs values roughly between 800 and 1600 and is slightly different on each channel. To find out which range your receiver has, open the Serial Monitor in the Arduino IDE to see the output of your RX. It will look similar to this:

channel 1: 728
channel 2: 729
channel 3: 703
channel 4: 726
channel 1: 1681
channel 2: 1639
channel 3: 1613
channel 4: 1676

Once you have a clearer idea of the range which your RX outputs, choose good approximations for hi and lo and alter the constants accordingly. Then upload the sketch to the Arduino again.

Calibrate the Emulated Joystick

Hook up the device to your computer and use the calibration function of your OS to calibrate the emulated joystick. A good tool for Linux is jstest-gtk.



Further enhancements

  • Write non-blocking code (see Step 3)
  • Set ranges per channel, not globally (see Step 6)

Further reading