Control the Flight Simulator option of Google Earth using an Arduino and Accelerometer.

Fly virtually around the world; tilting the Accelerometer forward, back, left and right to control the Plane's Pitching and Banking.

* Learn how to send Serial data from Arduino to Python
* Learn how to manipulate strings and lists in Python to read and interpret the data sent from Arduino
* Learn how to use the pywin library for Python to control Windows functions such as Mouse and Keyboard

We use Python as the interface between Arduino and Google Earth. In my Arduino / Raspberry Pi Internet Radio Instructable (https://www.instructables.com/id/Arduino-Raspberry-Pi-Internet-Radio/) we used nanpy on both Python and Arduino so that Python could issue commands to Arduino and read responses. Life would be boring if we always did stuff the same way, so in this project Arduino talks over Serial USB to Python by use of the pyserial library for Python.

If you don't have Google Earth on your PC download it from here:

BTW, you if you don't want to agree to Google Chrome becoming your Default Browser UNCHECK the box at the License Agreement stage.

Step 1: You Will Need

You will need:

* A Windows PC
* Google Earth installed on the PC
* Python 3.2 installed on the PC
* An Arduino Uno
* An Accelerometer (e.g. http://goo.gl/ZddGy )
* A prototyping system or breadboard to wire the Accelerometer to the Arduino (e.g. http://goo.gl/1E1iI)
* A small push switch

I've had some questions on how to add more buttons.<br> <br> Here's what you need to do:<br> <br> Add them on the board and wire them up, as with the one in the project. Connect them to some digital pins e.g. 7,8,9.<br> <br> See where swpin and swState are used in the Arduino code?<br> <br> Duplicate those lines and edit to represent a new pin/state e.g.<br> <em><strong>int&nbsp; swpin1 = 7;</strong></em><br> <em><strong>swState1 = digitalRead(swpin1);&nbsp;&nbsp;<br> ....</strong></em><br> <em><strong>pinMode(swpin1, INPUT);<br> digitalWrite(swpin1, HIGH);</strong></em><br> ...etc...<br> <br> Send that as a <strong>Serial.print(swState1, DEC);</strong> to Python.<br> <br> In Python; again make a new switch state e.g.: <em><strong>swState1 = int(data[4]) </strong></em>etc....<br> And duplicate and edit this section so it executes if swState1 is TRUE;<br> <em><strong>win32api.keybd_event(0x20, 0,0,0)<br> win32api.keybd_event(0x20,0 ,win32con.KEYEVENTF_KEYUP ,0)</strong></em><br> <br> That code section above specifies which key should be pressed and then released (0x20 = 32 decimal = SPACE in ASCII). If you want to activate other keys stick there ASCII Hex code in there instead.<br> <br> Good luck with it.
<p>Hi </p><p>I hv installed pyton32 bit on 64bit system</p><p>also installed pywin and pyserial</p><p>but after runing mouse.py file which i copied from this page </p><p><a href="https://www.instructables.com/id/Flight-Simulator-with-Arduino-and-Python/" rel="nofollow">https://www.instructables.com/id/Flight-Simulator-w...</a></p><p>I am getting this error </p><p>Nothing on COM 1<br>Nothing on COM 2<br>Nothing on COM 3<br>Nothing on COM 4<br>Nothing on COM 5<br>Nothing on COM 6<br>Nothing on COM 7<br>Nothing on COM 8<br>Nothing on COM 9<br>Nothing on COM 10<br>Nothing on COM 11<br>Nothing on COM 12<br>Nothing on COM 13<br>Nothing on COM 14<br>Nothing on COM 15<br>Traceback (most recent call last):<br> File &quot;C:\Users\MANGESH\Desktop\m.py&quot;, line 33, in &lt;module&gt;<br> rx = ser.readline().decode().split('\r\n')<br>NameError: name 'ser' is not defined</p>
<p>The Python program has not been able to read from a device on any of the 15 COM ports it tried. Then it gives up with the &quot;NameError&quot;.</p><p> Check the COM port shows up in the Windows Device Manager.</p><p> Make sure the Arduino code is loaded and running. </p><p>Try checking the serial connection from Arduino by using the Serial Monitor in the Arduino IDE. You should see stuff being written from Arduino.</p>
<p>I love the combination of Python and the Arduino. So I have created a collection about it. I have added your instructable, you can see the collection at: &gt;&gt; <a href="https://www.instructables.com/id/Arduino-and-Python-and-perhaps-a-Rasberry-Pi/"> https://www.instructables.com/id/Arduino-and-Pytho...</a></p>
<p>Traceback (most recent call last):</p><p> File &quot;C:\Users\sai kiran\Desktop\mouse.py&quot;, line 2, in &lt;module&gt;</p><p> import serial</p><p>ImportError: No module named serial</p><p>Can u please tell me why this error is occuring ?</p><p>it will help my main project.....</p>
can tweak this to android smartphone?
Added automatic detection of the COM port.
Amazing,I will try this soon. <br>btw,is windows necessary ? I have ubuntu 12.10 and windows as well,but can't this be used in ubuntu ? <br>As Arduino IDE,google earth,python are all available for ubuntu and so it should work. <br>
Thanks. It should work with ububtu if you have a python api for that. I specified windows because I used the win32 api which is obviously Windows specific.<br><br>Good luck with it.
I am trying to learn python now (I know, I am a a little late!), and after have a little insight in python in this, I will definitely try this! Thanks :)
I was a late starter myself with Python. Although very familiar with programming, I was looking for an all-round programming language and I think I found it with Python. I'd recommend trying out the commands you're trying to use in the IDLE command line. Errors show up immediately and you can find the correct constructs for what you're trying to achieve. I always keep : &quot;Programming Python&quot; O'Reilly , near by. Good Luck.

About This Instructable




Bio: Technologist, Electronic Engineer, sometime Coderdojo mentor.
More by akellyirl:Arduino Guitar Tuner Using DSP Techniques Add Amazon Echo Voice Control to You Smart Device Smart Home Thermostat 
Add instructable to: