Cleric-K / vJoySerialFeeder

Feed Virtual Joystick driver with data from a serial port
GNU General Public License v3.0
252 stars 55 forks source link

Arduino SBUS to USB HID Joystick #17

Closed Radrik5 closed 6 years ago

Radrik5 commented 6 years ago

Maybe it's not the right place to ask but it seems you know a lot in the field.

I wonder if it's possible to flash an Arduino board with something that takes IBUS/SBUS signal from the receiver and converts it into USB HID Joystick. So you could just plug it in and run the simulator. There is the Joystick library for Arduino and you have the Sbus_invert.ino sketch. If only we could combine them together :)

Is it theoretically possible or there are some hardware limitations or something? The demand for such board seems to be pretty high (it's a much better replacement for audio-usb converters) but I have found only two not very popular examples: one, two (in Russian).

Cleric-K commented 6 years ago

Hi,

for IBUS the solution already exists: https://github.com/wdcossey/flysky-ibus-leonardo.

The problem with SBUS is that it uses inverted voltage levels which is a problem in Arduino, because the hardware serial port of the Atmega microcontrollers does not support inverted signals. And software based serial port is simply not fast enough to read the 100 000 bps bitrate of SBUS.

Theoretically speaking, what you say (combining the software inverter (SBUS_invert.ino) with the HID part) is possible, but practically it won't work. The reason is that even for such a simple action as reading a pin and writing the inverted value to another (this is what SBUS_invert does) it takes as much CPU as it cat get and even optimizations were needed - otherwise it was not fast enough and it misses incoming bits. When the remaining code for the HID and serial is added it will simply not let the soft inverter run fast enough.

That's why the first example you sent requires Teensy. If you look at line 14 you'll see:

SBUSSERIAL.begin(100000, SERIAL_8E1_RXINV);

Pay attention to RXINV part, this is what tells that the port uses inverted signal on the receive pin. The ARM microcontroller of the Teensy supports this inversion in hardware. That's why it is no problem to do it.

So for Arduino there are two options

In both cases some extra work is required but the code of the second link should work.

Radrik5 commented 6 years ago

Thank you very much for the answer! I'm really excited that it's possible to make a small thing (with size of a USB flash drive) that connects your spare receiver to a PC and makes it a USB joystick!

I will try Arduino Micro with the hardware inverter (uninverted pin is not discovered for Radiolink R6DSM yet). Seems like hardware inverters were popular in the times of Naze32 flight controller, some of them are still available on Banggood and in other places.

Cleric-K commented 6 years ago

Ok, if you have problems with the arduino sketch you can write me, I'll try to help.

Good luck!

Radrik5 commented 6 years ago

Ordered Arduino board along with the inverter will arrive in 2-3 weeks, I'll let you know if it works.

I'm closing the issue for now to remove it from the list of open issues of your project. Thanks again!