Monday, October 31, 2016

Arduino with FSX (Part 5)

An 8-Axis 256-Button Arduino Joystick— 

The Arduino has been successfully programmed to act as a 128 or 256 button HID-USB device that can communicate through USB with a PC. Unfortunately, FSX has the limitation of 32 buttons/switches per USB device. However, if the 128/256 buttons can be partitioned as multiple joystick data streams, then the one Arduino can appear to be multiple 32 button joysticks to FSX. A different USB driver must be used on the PC that divides the Arduino data string into data strings from multiple joysticks, each with a different ID, and sends those data strings to FSX. FSX acts on the data as coming from individual joysticks. A 256-button joystick  programmed as dual 128-button joysticks is described later. Thirty-two buttons from each joystick can be used by FSX. Extra buttons beyond 32 are just ignored.

The original 40-button Arduino joystick was modified to 256-Buttons by Eagle forum member "overpro"  (ref: forums.eagle.ru/showthread.php?p=2522938). "overpro" developed Arduino hardware based on a pin matrix (16 x 16 = 256 pins) to provide the pins necessary to handle 256 buttons/switches. He also includes some dedicated pins for rotary encoder inputs. In post #150, "overpro" provides an Arduino sketch "CVP_JoystickController.ino" which creates the 256 button data stream sent over HID-USB to a PC. The associated "CVP_Joystick_1HID256Btns.hex" file is used to flash the HID-USB (see post #142 of the above forum). Also in the forum comments are references to Pointy's Joystick Test and Peter Dowson's HID device scanner (HID Scanner.exe). This forum has a wealth of information about the development of a large joystick but the forum discussion is lengthy, making it sometimes difficult to understand the best path forward.

In another forum thread (ref: forums.eagle.ru/showthread.php?t=117011, post #1), member "overpro" provides a fairly comprehensive explanation of a "composite" USB device that creates two joysticks from one Arduino HID-USB device.

I followed the above procedures using a Mega 2560 but without the 16x16 pin matrix. Both Pointy's Joystick Test and Peter Dowson's HID Scanner revealed the two 128 pin joysticks, and it was confirmed (by shorting pins to ground) that only the first 32 pins from either joystick were sensed by FSX. However, FSX did sense the two as separate joysticks, and each could have their pins assigned to different FSUIPC functions. Using "overpro's" code does provide a means of adding two 32-pin joysticks to FSX. One of the joysticks also handles the 8-axes which can be connected to potentiometers for control surfaces.

Sorting through all of the above details took several days of reading, prototyping, and testing.

Refinements I want to investigate to what has been developed by "overpro", "riclamer", and "Darran", include integration of rotary encoders as input devices, and port expanders for adding additional pins without using the pin matrix approach. I have no opinion whether port expanders are any better or worse than pin matrices, I just want to learn about port expanders and to integrate them into the discussion.

For FSX, it seems that the easiest approach using Arduino Joysticks is using 32 digital pins of a Mega 2560 for buttons/switches and 8 analog pins for control axes. Rotary encoders each require 2 digital pins, so 32 pins translates to a maximum of 16 encoders per Arduino joystick. Encoders are easily handled by MobiFlight, so maybe that is a better solution. The topic of LED displays used to show the state of a switch is discussed in various forums. I have read that USB can handle two-way traffic, but I have yet to read how LED's can be controlled on the Arduino by FSX. MobiFlight handles both LED and digital displays, which makes that even more attractive from that perspective. Future blogs in this series will investigate rotary encoders and port expanders in more detail. If anyone has examples of how to control LED's over HID-USB, please let me know. Thanks.

Useful references -




(Oct 31, 2016)

No comments:

Post a Comment