Connect a GPS to Raspberry Pi

Warning : This article has been automatically translated by Bing Translate


Danger : This article has been automatically translated by Bing Translate


Caveat : This article has been automatically translated by Bing Translate

Today ca is not really a tutorial but more tips to connect a GPS module to your Pi Raspberry. Indeed, the configuration is extremely simple thanks to the gpsd module.

Raspberry Pi Home Server - Connecter un GPS

Always for my mobile Raspberry project, I need to know the position regularly. So what's better than a GPS.

Add GPS to your Raspberry can be done in three ways (or more if you have any other ideas !) :

  • Achieve a GPS controller is even based on different components. Advantage : reduced cost, I think less than € 20. Only it is necessary, I think so, If either know or were afraid to enter.
  • Some such as Adafruit, offers ready to use maps (as here). It was quite tempting as you plug it on the GPIO and it controls everything. Just for me the price was a brake : map, an antenna, an adapter for antenna (It's a bit abused to sell it !) and possibly a connector for the USB port.
    The invoice amounts therefore to 57$ excluding postage.
  • The turnkey GPS module. Looking a bit I found that the BU-353 can connect on the Raspberry. All this for less than 40$ including postage ! Enough trying so.

Starting thus the principle that I will get may be not to assemble my DIY GPS, I did a ride on a Chinese resale site and the order was quickly placed. The model is an external module BU-353 that connects by USB, with a beautiful magnet underneath to fix or a suction cup that attaches to the cable. 37,80$ including shipping costs. Reception 10 days later :

Raspberry Pi Home Server - Connecter un GPS

Left to recognize by Raspberry Pi. And why nothing more simple :

  1. Update the system
    apt-get update && apt-get upgrade -y
  2. Install GPS management tools : GPSD
    apt - get install –y gpsd gpsd-clients python-gps

Voilà, thats all ! You have even what it takes to get there with a Python script.

To check you have the command cgps :

cgps s

Raspberry Pi Home Server - Connecter un GPS - gspd - cgps

And to read the data in Python, Here is an example found on the site of Dan Mandle :

#! /usr/bin/python
# Written by Dan Mandle http://Dan.Mandle.me September 2012
# License: LPG 2.0

import os from gps import *
from time import *
import time import threading gpsd = None #seting the global variable os.system('clear') #clear the terminal (optional)

class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope     gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info     self.current_value = None     self.running = True #setting the thread running to true    def run(self):
    global gpsd     while gpsp.running:
      gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer  if __name__ == '__main__':
  gpsp = GpsPoller() # create the thread   try:
    gpsp.start() # start it up     while True:
      #It may take a second or two to get good data       #print gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc        os.system('clear')

      print       print ' GPS reading'       print '----------------------------------------'       print 'latitude    ' , gpsd.fix.latitude       print 'longitude   ' , gpsd.fix.longitude       print 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time       print 'altitude (m)' , gpsd.fix.altitude       print 'eps         ' , gpsd.fix.eps       print 'epx         ' , gpsd.fix.epx       print 'epv         ' , gpsd.fix.epv       print 'ept         ' , gpsd.fix.ept       print 'speed (m/s) ' , gpsd.fix.speed       print 'climb       ' , gpsd.fix.climb       print 'track       ' , gpsd.fix.track       print 'mode        ' , gpsd.fix.mode       print       print 'sats        ' , gpsd.satellites        time.sleep(5) #set to whatever    except (KeyboardInterrupt, SystemExit): #when you press ctrl c     print "\nKilling Thread..."
    gpsp.running = False     gpsp.join() # wait for the thread to finish what it's doing print "Done.nExiting."

In case of problems to read the information from the GPS, the problem may come from the rights on the file used in/dev (often/dev/ttyUSB0). To remedy, You must modify the file /lib/udev/GPSD.hotplug by adding the line

chmod a   rw $DEVNAME

before the line

gpsdctl $ACTION $DEVNAME

(source of the trick : here)

Here is your mobile Raspberry, autonomous (Thanks to the power supply with 6 batteries explained in this article) connected with GPS :

Raspberry Pi GPS

You will notice the small red light on the GPS that indicates good food. It remains fixed until the signal is attached. When the position can be received, light starts to Flash.

En espérant vous avoir un peu aidé pour vos projets 🙂

Like this article ? Bear with me on patreon!

You may also like...