Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Changes

Jump to: navigation, search

Howto:Use Arduino with FlightGear

91 bytes removed, 10:28, 10 February 2015
Some more
Thanks to [[FlightGear]]|FlightGear's ]] [[generic protocol]], hardware can easily interface with FlightGear. This hardware can be used to improve the immersion and/or realism of the simulation. Arduino is no exception.
== About Arduino ==
=== Input protocol file ===
Input protocol file is used to specify how serial information is read by Flightgear. In Ubuntu protocol files are found in:
<ttcode>''/usr/share/games/flightgear/protocol''</ttcode> directory.
==== Protocol file structure ====
Create <ttcode>''controltest.xml''</ttcode> file in your protocol folder and paste code from below to it.
<syntaxhighlight land="xml">
<?xml version="1.0"?>
See [[Generic protocol]] for a description of the various XML tags.
===Wiring and coding Arduino===
====Wiring====Potentiometer A potentiometer is connected to Arduinos ground and +5 volts. Potentiometers The potentiometer's middle connector is connected to A0 analoq input. Switch is connected to ground with 10 kOhms pull-down resistor and +5 and digital pin 7.[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting the potentiometer and switch to Arduino]]
====Code====
Copy this code to Arduino IDE and send it to Arduino Uno:
<syntaxhighlight lang="c">
</syntaxhighlight>
====Test Testing serial output==== 
Use Arduino IDEs serial monitor and you should see something like this:
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDEs serial monitor output]]
First The first number is switch data, so it's either 0 (switch off) or 1 (switch on). After the "," mark is our throttle data. First it's 0.00 , which meaning idle throttle and then potentiometer is gradually turned until it reaches 0.99.
{{Warning|Remember to '''unplug Arduino's USB cable and plug it back''' in because Flightgear won't be able to read serial without doing this! You have to do this every time after you use Arduino IDE.}}
====Start FlightgearFlightGear ==== 
Flightgear needs to be started with a correct command line option for it to be able to read serial connection. This example uses following option:
--generic=serial,in,30,/dev/ttyACM0,controltest
If you like, you can use graphical user interface, Flightgear [[FlightGear Launch Control ]] (aka FGRun), to launch Flightgear. Select the correct settings from Advanced Option tab. [[File:Starting Flightgear with input options enabled.jpg|thumb|none|Starting Flightgear with FGLaunch ControlFGRun, selecting input/output options]]
If you don't now know your correct port, you can check it with a following command in terminal: dmesg | tail. It should give you a message something like: "ttyACM0: USB ACM device" or "ttyACM1: USB ACM device". That's your port. Finally save setting by clicking 'OK' and click 'Run' to start flightgear. For a more detailed guide, see [https://sites.google.com/site/flightgeararduinoandlinux/home Flightgear, Arduino and Linux]
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]
== Display/Generic protocol Example by rubdos == {{usr|Rubdos }} (Ruben De Smet) has built an example using the [[Generic Protocolgeneric protocol]] and an Arduino Mega 2560.
The code used to control the Arduino with generic protocol was:
<syntaxhighlight lang="xml">
<?xml version="1.0"?> <PropertyList> <generic> <output> <binary_mode>false</binary_mode> <line_separator>newline</line_separator> <var_separator>newline</var_separator> <preamble></preamble> <postamble></postamble> <chunk> <name>Altitude</name> <node>/position/altitude-ft</node> <type>integer</type> <format>altitude=%i</format> </chunk> <chunk> <name>RPM</name> <node>/engines/engine/rpm</node> <type>integer</type> <format>rpm=%i</format> </chunk> </output> <!-- <input> <line_separator>newline</line_separator> <var_separator>tab</var_separator> <chunk> </chunk> </input> --> </generic> </PropertyList>
</syntaxhighlight>
It is a simple plaintext protocol, which can easily be parsed by an Arduino. The code used on the Arduino is available on github as a gist: [https://gist.github.com/rubdos/5422870]

Navigation menu