ArdsimX Tutorial #2: Elevator Trim LED Bar

The goal of this tutorial is to teach you how to modify your ArdsimX Arduino code for 3rd party libraries and utilize somewhat more external electronics in your sim. Our task here is to add an LED bar graph trim tab to work with X-Plane 11 to show us where the trim elevator is currently set. I set up my stick thumb control for trim nose up and nose down, but you can use the virtual control on your aircraft as well.

When I built the original version for my sim, I did it the hard way, by individually wiring up each LED  to a digital output of one of the Arduino Megas. Mostly, because I didn’t want to take the time to figure this out. But now that it all works, I’m working to improve the sim one step at a time. Real compared to sim version, below. I added this to my sim to match the Diamond DA20 trainer.


Step 1: Gather Materials
(1x) Arduino Uno
(1x) LED bar graph module

On Amazon and Ebay, I found a few different LED bar graphs, some multi-colored. I used solid red module, to match the DA20. The modules are simple to use with an LED controller built onto the board. It only uses 2 pins for control, one for clock and one signal pin.

Step 2: Wire up your parts
Connect the LED as normal to the Arduino. Connect outer pins to GND and +5V and the center pin to one of the analog inputs, I’m using Analog Input #1 (A1). Here’s a picture of my setup. <BR>

Step 3: Find Dataref and write your config file.
I found the Dataref using the Configurator. No need to jump into the Dataref viewer for this one. I’m using sim/cockpit2/controls/elevator_trim. The data.cfg file is very basic. In the Output [O] section, we are sending the dataref signal out.

————-Copy code below and save as data.cfg in your ArdsimX Plugin Folder——————–

 

What’s happening under the hood:

  • 1 = The ID of the output, used by the ArdsimX Arduino code to register which output. This has nothing to do with the pin number. Once you get used to this, it’s pretty easy to read.
  • 3 = Indicates that we’re sending a float. A ‘1’ would indicate that we’re sending a Boolean value, for reference.
  • And sim/cockpit2/controls/elevator_trim  is the [val] variable we’re sending on ID 1. This will make more sense in the next section, when we review the Arduino code.

 

Step 4: Upload your Ardsimx code to your Uno.

————-Copy Code in your Arduino IDE and Upload onto your Arduino——————–

The lines below add the Adeept_Bar library to the ArdsimX standard sketch. This enhances to abilities of ArdsimX to utilize 3rd party libraries and hardware. Pins 2 & 3 are used to communicate with the LED bar.

I commented out the use of ethernet as my Arduino UNO is connected via USB. Otherwise, just added these lines to the setup, which the LED bar needs. I pulled this from the example code which came with the LED module.

Here’s the meat of the the addition. Anytime you want to send custom data to or from your Arduino, you need to add it into the  void ProgOut(byte id, float val)  function. This took me awhile to get the hang of, but it’s pretty simple. Try not to overcomplicate it for yourself.

There are two variables, id and val. From your data.cfg file,ID refers to this line.
1 3 sim/cockpit2/controls/elevator_trim

When ID=1, Val will equal whatever value is coming from the Dataref for elevator_trim. Here’ I’m using If statements to filter the value. For example, this line will set the center LED to glow, representing the Trim in the neutral position. if (val < 0 && val > -.05) bar.setBits(0b000000000010000);

Step 5: Taking This Further
Now that you’ve had some experience modifying the basic Arduino code for ArdsimX, try other hardware and software libraries. There are many off-the-shelf hardware components ready to be used with flight simulators that will be much easier now to use with ArdsimX. I would love to hear what you came up with. Please post a comment if you have any trouble making this work. .

Permanent link to this article: http://m1sims.com/2018/03/11/ardsimx-tutorial-2-elevator-trim-led-bar/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.