How to Talk to Garmin GPSMap 60CSx using Python

I haven’t blogged in a while. But I haven’t been idle at all.

Part 1) A month ago, I was working on a project where I had to collect GPS coordinates of a 25-acre piece of land. Real survey information was not needed but I had to show the outline of my project site on a variety of maps. I thought to myself – “Wouldn’t it be nice to be able to take the laptop running ArcGIS to the field, hook it up to my handheld GPS, and plot your GPS location in realtime?” – So what were my options ?

1) Google Earth offers such capability using a very straightforward process, especially if you’re using a Garmin GPS. With a few clicks you’ll be op and running. Directions are here. Unfortunately, this only works well while you’re connected to the web, and my laptop has no wireless service to allow it to work in the middle of nowhere.

2) Since most of my GIS work has been with ESRI (I’ve had my share of annoying freezes and crashes lately!), I was hoping for an ArcMap solution. In fact, there is a .NET project by Edan Cain for ArcGIS Explorer. I spent some time installing & uninstalling Explorer and subsequently the entire ESRI suite, only to run into the same non-descript error when I tried to run the script. I had similar bad luck with another similar tool for ArcMap.

3) GPS Trackmaker (it’s free!) worked well when it comes to displaying your current position as provided by the GPS. But getting it to accept my existing shapefiles as basemaps was too much of a headache to warrant further efforts. If you know the secret of how to get this to work, please let me know.

Part 2) – By now, I was frustrated enough with the “big packages”. Why not try to coomunicated with the GPS using Python, and then be able to work with the data, if not in realtime, at least at your discretion. Surely, this would just be a matter of locating a few modules and writing a few lines of code. In fact, there are plenty of examples on the web, and I also found one in Mapping Hacks on my shelf.

When downloading waypoints to Garmin’s Mapsource software or third-party utilities, I’ve always used the USB cable. But for use in Python, I quickly found people were saying reading from USB was a lot more complicated than from the serial port. There is a USB module – pyusb. But I had no luck with it. Most people seemed to be having success with serial.py, a Python extension for the PC’s serial port. So I ordered a serial cable which hadn’t originally been included with my GPS. When

However, something as simple as:

>>> import serial
>>> ser = serial.Serial(0)  #open connectionto COM1

didn’t work. When I checked what I had actually installed, I found there was no serial modules but one called serialwin32 in a folder serial. Using the following worked.

from serial import serialwin32

Then I tried:

s = ser.readline()

and nothing happened. I am not sure I have ever used my serial port before. My PC is only 2 years old. So I had to make sure I knew which port was COM1. I finally had to check BIOS settings to make sure they were ok.

I abandoned my work using serial.py, and looked at gpsd, a Linux daemon that can be run with cygwin under Windows. I installed this version and Cygwin, and tried to use the Python wrapper (gps.py) that comes with  it, but soon got bogged down in strange errors and missing modules.

I had similar problems using Pygarmin, which sounded like a dream come true. It was designed for use with Garmin GPS technology and included a set of classes for the NMEA specificiation. But it appears this module has not seen any development in some time, and it didn’t work for me. Same with pygps. I spent time installing and got sidetracked searching for missing modules related to GTK. My last ditch effort was to use a Python wrapper for GPSBabel. But no luck here either.

Instead, I tried the initial serial.py script one more time, and then decided to see if I could check on the status of COM1 while the GPS was plugged in. A handy toll for that is Comtest. While the script did nothing, Comtest showed me some output that looked like this:

@100430190019_____________________@100430190019___________________

That’s YYMMDDGMT ! Somebody was talking to COM1 !!

Then, it occurred to me that I should replace ser.readline() with ser.read(). And wham-bam, I was in business.

from serial import serialwin32
ser = serialwin32.Serial(0) 
print ser.portstr 
s = ser.read(1000)  
print s
ser.close()
  

The GPS was set for TEXT output mode at 9600 baud, and I was getting strings of text like this line:

@100430190020N3341662W09207282G012+00209E0044N0025D0048

Date Time                 Latitude    Longitude     Gobbledeegook

Granted, I spent a lot of time to get something this simple to work. Some of it because I didn’t know much about serial ports, some of it because I got sidetracked trying out different scenarios. But I learned a lot more than what was needed to get a solution, and I have made a long list of things. This is what I love about teaching myself programming skills. You started at A, wanting to go to B, and you get there via Z. Needless to say, I need to spend some more time trying to get pygarmin.py and nmea.py to work.

Advertisements

4 Comments

Filed under Uncategorized

4 responses to “How to Talk to Garmin GPSMap 60CSx using Python

  1. Edan Cain

    Hi, someone blogged about my work, nice, thanks very much.
    Hey so I think I know what your problem was, for most garmin devices you need to download and install the Garmin Spanner application. Basically allows communication via a virtual port. Make sure that you set your garmin to output NMEA, and try again to get a connection going.
    Hope this helps.

    Kind regards,
    Edan Cain

    • Arne

      Hi Edan,

      thanks a bunch. I wish I’d tried to get in touch right away. That might have saved me some headaches. I’m not a programmer at all, and am just trying to pick up as much as I can while working in GIS. Admittedly, I got a little carried away there with my GPS quest. I finally got it to work using a simple Python script and the serial port… but I will definitely give your project another shot there. Thanks for your comment !!

      Arne

  2. It is always great to share the innovative ideas with others on our demand.That is the main way for the people to know about the good types of techniques to equip it.

  3. henrikswe

    Hi Arne!

    Which kind of serial cable did you use? There seems to be a bunch of them out there and I can’t figure out which to choose… I suppose it’s some kind of “garmin serial data cable”.

    I’m glad that you shared this information! I have been thinking about doing a python program that can handle a garmin 60CSx for a long time now.
    My main thought are to do a program that can get my waypoints and tracks and store them in some kind of database. I have tried some of the thing you describe with the same results and pretty much came to the same conclusions.

    Henrik

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s