RPi Car Computer Part 6: GPS Setup

Raspberry Pi LogoWhat good Car computer does not have a GPS and maps? Definitely not one worth it’s money. So in our project we will add a gps receiver and program it so we can get a location from it.

There are quite a few ways to connect the Raspberry Pi with a GPS receiver:

  1. Using a bluetooth GPS and the bluetooth dongle we already setup
  2. Using a GPSHat from Adafruit (or something similar)
  3. Using a USB GPS and permanently occupy one of your USB ports.

Well my solution is using a USB GPS receiver. I noticed that you can get them cheaper on ebay rather than amazon so I am linking the one I bought here but again as with previous hardware suggestions, I am not endorsing nor promoting the specific hardware. Just stating what I bought.

Now the reasoning behind buying a USB GPS receiver is simple. All three of the solutions will use the NMEA protocol so the programming behind the connection will be the same in all three. THe GPS HAT connection will be require a bit more work to setup (wiring etc) and bluetooth GPS receivers will occupy Bluetooth positions and also requires extra outside powering. Bluetooth GPS receivers usually have their own battery which eventually will run out and require charging. The USB GPS  receiver gets power from USB port and it is more or less plug and play. So I think you understand why I am choosing this solution.

If you noticed in the above paragraph I mentioned the NMEA protocol. Well the NMEA protocol is a combined electrical and data specification for communication between marine electronics such as echo sounder, sonars, anemometer, gyrocompass, autopilot, GPS receivers and many other types of instruments. It has been defined by, and is controlled by, the National Marine Electronics Association. NMEA 0183 replaces the earlier NMEA 0180 and NMEA 0182 standards. In marine applications, it is slowly being phased out in favor of the newer NMEA 2000 standard.

Now cheap off the shelf GPS receivers are using this protocol. How the protocol works and what information it provides can be found here. I had started working on a python library that parses and gets Latitude and Longitude from this NMEA data but, guess what, this already exists… So all the work goes in the garbage. Then again why not use something that is already perfected?

So back to our setup. Connect the usb gps to a usb port, place your pi close to a window, put the gps receiver outside so it can have a clear view of the sky and turn on your pi.

Open up a terminal window and type:

sudo lsusb

You will probably see something like the following

lsusb gps

 

As you see our USB GPS is the U-Blox AG. Now let’s install our stuff.

Run the following command

sudo apt-get install gpsd gpsd-clients python-gps

When this finishes execute the following command

sudo gpsd /dev/ttyACM0 -F /var/run/gpsd.sock

So more or less this it. Everything is setup now. Simply run cgps -s and you will see a screen like the following

 

gps coords

There. Everything is setup now. Next thing we will create a software that will use that position we are acquiring from your GPS receiver, and a map of our area to navigate around.

 

Disclaimer: If what you are getting is all zeros and it times out after a few seconds then there is something different with your setup. 

Your device may not be connected with ttyACM0  but rather with ttyUSB0 or even ttyAMA0

I cannot honestly predict that so when typing this command

sudo gpsd /dev/ttyACM0 -F /var/run/gpsd.sock

before typing ACM0 press the tab button twice, then you will get all possible suggestions (they are many) ignore all those that are simply ttyX (where X is a number) and try the rest. One of them is bound to work 🙂

One Comment

Leave a Reply