Monday, October 17, 2016

Arduino with FSX (Part 2)

Trim and Flaps Control — 

Trim and flaps are basic to flying any aircraft. I found trying to adjust trim and flaps using the mouse or keyboard keys while flying with a stick was very difficult and unnatural. I wanted to adjust trim using trim 
wheels and the flaps to be controlled by moving a lever up and down to provide the various flap positions required for flying.


The options that I found on the internet were: 1) commercial control boxes; or, 2) various plans for DIY constructed control boxes. Since I like to build things, I chose the latter option. The next question was how would it work? 


I found that most users referenced and relied on a software product, FSUIPC, and that it was an essential software tool. 

I found another software product, MobiFlight, which used an Arduino Mega 2560 with the MobiFlight software through USB to interact with FSX via FSUIPC. This seemed like an attractive approach since it used an Arduino as the controller computer, it had a user-friendly interface, and it connected to the PC running FSX through USB.


The first road block I found was that MobiFlight did not connect to potentiometers, but did connect to rotary encoders. I had to learn about rotary encoders.


I ordered KY040 rotary encoders from eBay, and while I was waiting for them to arrive, I watched the Mobiflight you-tube training about constructing and testing hardware for FSX. That seemed like a solid approach. When the KY040 rotary encoders arrived, I successfully tested them with Mobiflight to send trim signals to FSX. Once that testing was completed, I ordered Arduino Mega 2560 boards from eBay. The first two boards I received were not Arduino boards even though the description on eBay stated they were R3 Mega 2560 boards. Instead they used CH340 USB chips and the clock ran on a 12 MHz crystal, rather than 16 MHz. It turned out that MobiFlight ran fine on these knock-off boards, but I decided to place another order for R3 Mega 2560 boards from an eBay vendor that documented their boards used the proper USB chip. The critical difference in these boards is the USB controller chip. The CH340 USB chip in the knock-off board is a dedicated serial-USB chip which works for most vanilla Arduino applications. The Arduino Mega uses the ATmega 16U2 USB chip which can be reprogrammed to be serial-USB or HID-USB. HID-USB will be discussed in later blogs about building joyStick devices.

 


The Arduino Uno and Mega 2560 use the ATmega 16U2 USB chip (left picture) which can communicate through, and be programmed through the USB-ICSP pins. A clone board that uses a CH340 Serial-USB chip (right photo, 16-pin IC) does not have the USB-ICSP pins. One other thing, while discussing eBay Arduino boards--some knock-off boards use chips that are not pre-programmed. You may have to program the USB chip or the main processor chip to make the board work as an Arduino. It can be distressing when you get your new board, plug it in, and it just does not work. It takes some time to figure out if there is a hardware or software problem. And it takes more time to fix the problem, if it can be fixed.

Working Trim-Flaps-Gear Controller Prototype --


I fly using a stick in my right hand. I wanted to control trim, flaps, gear, hook, and speed brake with my left hand, as used in some Navy aircraft. The picture shows how I assembled these functions into one box that can be mounted for left hand use. The Trim, Flaps, and Gear Control Box continues to be a work in progress, but it has become fairly mature. The Control Box, with Arduino Mega 2560 and MobiFlight, now provides:
  • Elevator Trim Wheel using KY040
  • Aileron Trim Wheel using KY040
  • Rudder Trim Wheel using KY040
  • Flaps Control using 4 position rotary switch
  • Gear Control using 2 position rotary switch
  • Speed Brake using DPDT toggle switch
  • Tail Hook using DPDT toggle switch
  • 4 LED's for flap position indicators
  • 3 LED's for gear position indicators
  • 1 LED for speed brake position indicator
  • 1 LED for tail hook position indicator
  • 8-digit readouts for elevator trim count and % elevator
  • 8-digit readouts for aileron trim count and % aileron
  • 8-digit readouts for rudder trim count and % rudder
My first build focused on the Trim wheels using rotary encoders. Flap and gear switches and LED's were then added and tested. After struggling with trim during flights, I added the out-board displays so I could better understand how trim was affecting the flight simulations. Initially I had a few problems when controls did not respond quickly while flying simulations, such as, flaps down on approach. This problem was fixed by turning off debug logging (both in FSX and MobiFlight) which interfered with control actions being taken in a timely manner.
MobiFlight uses FSUIPC offset addresses for many actions. Therefore, purchase a license for FSUIPC, so that you will have that tool available for use in all your controllers.

TODO - 

1) Figure out how to check the position of a switch and reset FSX to use that switch setting, in case the initial switch pulse was missed due to the processor being busy and missing the switch.

2) MobiFlight Control Mapping - make a table of the control, the Mobi device, the FSX control, the control mode (keypress, FSUIPC offset, FSX direct), size (byte, word, int4, int8), value (0,1, 16384, etc), transforms, pre-conditions.

(Oct 17, 2016)


    1 comment: