2,732
edits
(→Testing serial output: Warning → Tip – Since there are no software crashes, broken hardware or injuries) |
Red Leader (talk | contribs) (More cleanup) |
||
Line 1: | Line 1: | ||
Thanks to | Thanks to FlightGear's [[generic protocol]], [[:Category:Hardware|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 == | == About Arduino == | ||
'''[http://www.arduino.cc/ Arduino]''' is an open-source electronics prototyping platform based on flexible, easy-to-use | '''[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}}]. | ||
== Controlling | == Example 1: Controlling internal properties == | ||
This example demonstrates the use of a switch and a potentiometer to control the [[Property Tree]] | <big>By {{usr|Vaipe}}</big> | ||
This example demonstrates the use of a switch and a potentiometer to control the [[Property Tree]]. | |||
=== Equipment and software === | === Equipment and software === | ||
The following equipment was used for this example: | |||
* [[Changelog_3.2|FlightGear 3.2]] | * [[Changelog_3.2|FlightGear 3.2]] | ||
* [[ | * [[FGRun]] | ||
* Arduino | * [[Cessna 172P|Cessna 172P Skyhawk]] (default aircraft) | ||
* Linux (Ubuntu 14.04) | * [http://arduino.cc/en/Main/ArduinoBoardUno Arduino Uno] | ||
* | * Linux ([http://en.wikipedia.org/wiki/List_of_Ubuntu_releases#Ubuntu_10.04_LTS_.28Lucid_Lynx.29 Ubuntu 14.04]) | ||
* Simple on/off switch | |||
* Potentiometer | * Potentiometer | ||
=== Input protocol file === | === Input protocol file === | ||
Line 55: | Line 57: | ||
==== Wiring ==== | ==== Wiring ==== | ||
A potentiometer is connected to Arduinos ground and +5 volts. 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. | A potentiometer is connected to Arduinos ground and +5 volts. 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. The diagram below illustrates the setup. | ||
[[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting the potentiometer and switch to Arduino]] | [[File:Arduino switch and potentiometer wiring.png|frame|none|Wiring schematic for connecting the potentiometer and switch to Arduino]] | ||
==== Code ==== | ==== Code ==== | ||
Copy this code to Arduino IDE and send it to Arduino Uno: | Copy this C code to Arduino IDE and send it to the Arduino Uno: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
/* | /* | ||
Line 126: | Line 128: | ||
==== Testing serial output ==== | ==== Testing serial output ==== | ||
Use Arduino | Use Arduino IDE's serial monitor and you should see something like this: | ||
[[File:Flightgear arduino serial monitor.png|frame|none|Arduino | [[File:Flightgear arduino serial monitor.png|frame|none|Arduino IDE's serial monitor output]] | ||
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. | 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. | ||
Line 138: | Line 140: | ||
==== Start FlightGear ==== | ==== Start FlightGear ==== | ||
===== Method 1: Command line ===== | |||
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: | |||
<syntaxhighlight> | |||
--generic=serial,in,30,/dev/ttyACM0,controltest | --generic=serial,in,30,/dev/ttyACM0,controltest | ||
</syntaxhighlight> | |||
===== Method 2: FGRun ===== | |||
Alternatively, you can use FlightGear's graphical user interface (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 FGRun, selecting input/output options]] | |||
If you don't 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] | If you don't 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] |