Python and GPS Tracking Tutorial

Check out my intro to Python tutorial and GPS tracking program.

Favorited Favorite 3

If you have ever programmed a microcontroller, you are probably familiar with sending and receiving data over a serial port. A common way to do this is with a serial terminal program (hyperterminal, Arduino serial monitor, etc.). Lets say you want to create your own serial terminal program that displays data from a microcontroller in a meaningful way. For example, graphing temperature over time or displaying GPS position on a map.

There are many different programming methods to do this, one of which is Python. It is free, easy to setup, and has a massive user community with examples, forums, and tutorials.

alt text

Showing a trip from SparkFun to Boulder, CO.

Recently, I wanted to create a graphical interface to display GPS position for a high-altitude balloon radio system. I had so much fun and immediate success with Python, I decided to write a follow-along tutorial that helps you install Python, then shows you how to create a simple serial terminal program to send and receive data over a serial port. The tutorial ends by showing you how to run my GPS tracking program. Check it out!


Comments 17 comments

  • Chandhooguy / about 12 years ago / 2

    Track my friends EVERYWHERE they go!

  • Member #958037 / about 8 years ago / 1

    I tried with this code in the text editor but I got this message, when trying to run it:

    Traceback (most recent call last): File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 275, in open self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK) FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyS8'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/home/pi/gpsy.py", line 25, in <module> init_serial() File "/home/pi/gpsy.py", line 19, in init_serial ser.open() #open the serial port File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 278, in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException: could not open port 8: [Errno 2] No such file or directory: '/dev/ttyS8'

    What's the reason for this?

  • Member #36671 / about 12 years ago / 1

    Python and Arduino/MSP430 is RIDICULOUS AWESOMENESS, especially for prototyping/end products. You just make the mcu an input or output.

  • TimZaman / about 12 years ago * / 1

    I should note there is a distributed tracker already made for this, with all the radio-decoding embedded, a great web interface and such. It's at http://ukhas.org.uk/projects:dl-fldigi . and the tracker is at http://spacenear.us/tracker/ . Hacking this yourself (especially in the case of high altitude baloons) is a bad idea - you don't want to lose your balloon due to a few dumb mistakes. In this case, i don't see any latitude or longitude characters involved (N/S,E/W) for example.

    • In addition to Aaron's reply, I'd like to say that I've used the spacenear.us tracker for the last few of my launches. The big difference is that it is used primarily in the UK where there are a lot of listeners in a very dense area, as well as pretty broad cellular data coverage.

      Here in the US, especially in the plains of Colorado, there aren't many hams to listen and the cellular coverage - especially data - is nearly nonexistent. That's not to say it isn't a terrific piece of software!

    • Thanks for the links. Although that tracker is based on having an internet connection. I wanted something that could work without internet.

  • jmlynesjr / about 12 years ago / 1

    I use Perl and the Device::SerialPort::Arduino library from CPAN. This is very easy to use also.

    I use the chipKIT UNO version of the Arduino family.

    James

    • Device::SerialPort::Arduino

      Oh, nice. I've used Device::SerialPort for a couple of projects, and it's definitely handy. Cool to see there's an Arduino-specific extension to that.

      Viva Perl!

  • TheRegnirps / about 12 years ago / 1

    Nice job. Python has become the preferred language for serious scientific programing with great Physics and Math libraries, pyODE, pyQt, tKinter, cython (a binding to fast c libraries), and everything else under the sun. Learning Python is a solid investment and you will find it in the code provided at academic gatherings on everything from AI to medical seizure monitoring and massive ad-hoc networking research. Last year I was able to hook up a GPS module to a little Mini2440 running Linux (Debian) and get sensible output in a matter of minutes. Awesome. And installing was just "apt-get install python" and I think pySerial. I'll definitely have a look at your application. Debian + Python on small Linux boards has proven the most productive thing for me since Forth faded in popularity (a long time ago in a galaxy far far away).

    • TimZaman / about 12 years ago / 1

      Sorry, serious scientific programming is most often done in Matlab, especially prototyping. But a Matlab licence can set you back a few thousand $. That's where the term 'serious' comes in.

      • TheRegnirps / about 12 years ago / 1

        Everyone who does this stuf has Matlab available if they need it. I suppose it could be 10 or 12 years since you seriously looked at the citations in the literature. Try any random paper that gets plenty of citations, like this one, http://scholar.google.com/citations?user=XWpFf0IAAAAJ&hl=en and see where it leads.

        • Figs and beans to Tim above. I work in industry, and yup, we have Matlab and all sorts of add ons, all blisteringly expensive. Good stuff, and a lot of our work requires something with that sort of power.

          But a huge part of Matlab's functionality is available in Octave, which is open source, and yet I assure you it is serious. I don't pay for a Matlab license because I don't need the fancypants add-ons. The EEs down the hall do. Not paying money you don't have or need to spend is pretty 'serious'.

          This stuff about serious scientific programming most often done in Matlab sounds like someone making noise like 'I use it, so it is bestest! WOOT!".

          You use what works. If it works, and it is not expensive, or better, is free, then you win even bigger.

          I am a scientist. I do scientific programming, and I am real darn serious about it. I use what makes sense. I like Matlab, and think it is great. For some things. Sometimes. But if I can get what I want from Octave, I'll download it, and leave Matlab and its acolytes to themselves.

          And Python is far more portable, is a much less ugly programming language, is easy to embed on small systems, and is used by NASA and NOAA and lots of seriously scientific places. If I have a fuss about Python, it is the uncertainty about how much of my work I will have to redo when I finally have to migrate from 2.7 to 3.x

          • noworries / about 12 years ago / 1

            Another benefit of open source software is the freedom to install it on multiple computers without worrying about dongles, buying multiple copies of software, etc.

    • Chandhooguy / about 12 years ago / 1

      I agree. Although I wouldn't consider myself an "expert" on the Python language, I have played with it and have found it a very powerful language that I can use for a multitude of different projects.

  • D_C / about 12 years ago / 1

    Thank you so much, I am going to try something similar with an Arduino (don't have the money for a gps unit)

  • This is great! I just completed a course in Python, and was wondering what to tackle next. Thanks for this!

Related Posts

GEO Week 2024

GIS Day Sale

Um, Correction!

Recent Posts

Tags


All Tags