Changes

Jump to: navigation, search

Howto:Use Arduino with FlightGear

2,815 bytes added, 05:35, 26 December 2017
Added simple 2-axis tutorial by Scott.
'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. The hardware is a microcontroller designed around an 8-bit or 32-bit microcontroller, with several digital and analog {{Abbr|I/O|Input/Output}} ports. The software is the [http://arduino.cc/en/Main/Software Arduino {{Abbr|IDE|Integrated Development Environment}}].
== Example 1: 2-axis joystic ==<big>By ScottBouch</big> This example demonstrates use of two potentiometers (2-axis joystic) with a simple calibration in arduino code. Example is done with Linux Mint. To see more detailed version of this quide go to [http://www.scottbouch.com/flightgear-sim-arduino-serial-hardware-2-axis-potentiometer-joystick.html 2-Axis Potentiometer Joystick:Integration With Flightgear Flight Sim]. === Wiring ===Connect 5V to other terminal of potentiometers and 0V to other terminal. Connect potentiometers wiper terminals to Arduino boards A0 and A1. === Arduino code ===<syntaxhighlight lang="c">/*Flightgear hardware integration 01: Stick X and Y only so far. Scott Bouchard UK www.scottbouch.com 14-06-2017*/ const int stickxio = A0; //Define stick aileron (x) inputconst int stickyio = A1; //Define stick elevator (y) input float stickx = 0; //Start aileron (x) centralfloat sticky = 0; //Start elevator (y) central void setup() { Serial.begin(9600); //Open up serial communication to PC} void loop() { stickx = (analogRead(stickxio)/512.0)-0.99; //Calibration span and offset sticky = (analogRead(stickyio)/512.0)-0.99; //Calibration span and offset  Serial.print(stickx); //Send aileron position Serial.print(","); //Variable (var) separator Serial.print(sticky); //Send elevator position Serial.print("\n"); //Line separator }</syntaxhighlight> === Calibration ===Use Arduino serial monitor to see that serial data acquired from Arduino board is between -1.00...1.00 when potentiometers are rotated. Potentiometers middle position should send 0.00. If potentiometers are not giving good readings, modify Arduino code "Calibration span and offset" row to fix it. === Flightgear protocol code ===Create a file called hardware.xml to /usr/share/games/flightgear/Protocol directory and paste following lines to it: <syntaxhighlight lang="xml"><?xml version="1.0"?> <PropertyList>  <generic>  <input> <line_separator>\n</line_separator> <var_separator>,</var_separator>  <chunk> <name>aileron</name> <type>float</type> <node>/controls/flight/aileron</node> </chunk>  <chunk> <name>elevator</name> <type>float</type> <node>/controls/flight/elevator</node> </chunk>  </input>  </generic> </PropertyList></syntaxhighlight> === Make Flightgear to read serial data ===Find port where Arduino is connected. Look from Arduino IDE Tools... Serial Port... Should be something like ttyACM. (Note: Scott Bouch tutorial uses FGRUN which is not used anymore) Start Flightgear and paste following code to Settings... Additional settings... when starting Flightgear. Change serial port to correct port name. <syntaxhighlight>--generic=serial,in,30,/dev/ttyACM0,9600,hardware.xml</syntaxhighlight> == Example 2: Controlling internal properties ==
<big>By {{usr|Vaipe}}</big>
It should give you a message something like <code>ttyACM0: USB ACM device</code> or <code>ttyACM1: USB ACM device</code>. That is 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]
== Example 23: Outputting properties ==
<big>By {{usr|Rubdos}}</big>
[[File:Arduinofgfs.jpg|thumb|270px|Arduino LCD panel displaying speed, heading and altitude.]]
23
edits

Navigation menu