├── gps-neo-6m-board-schematic.png ├── 00532_Raspberry_Pi_NEO-6M_GPS-Modul_-_Schaltplan.png ├── Neo6mGPS.py ├── gpsdData.py └── readme.md /gps-neo-6m-board-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FranzTscharf/Python-NEO-6M-GPS-Raspberry-Pi/HEAD/gps-neo-6m-board-schematic.png -------------------------------------------------------------------------------- /00532_Raspberry_Pi_NEO-6M_GPS-Modul_-_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FranzTscharf/Python-NEO-6M-GPS-Raspberry-Pi/HEAD/00532_Raspberry_Pi_NEO-6M_GPS-Modul_-_Schaltplan.png -------------------------------------------------------------------------------- /Neo6mGPS.py: -------------------------------------------------------------------------------- 1 | import serial 2 | import pynmea2 3 | 4 | def parseGPS(str): 5 | if str.find('GGA') > 0: 6 | msg = pynmea2.parse(str) 7 | print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units) 8 | 9 | serialPort = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) 10 | 11 | while True: 12 | str = serialPort.readline() 13 | parseGPS(str) -------------------------------------------------------------------------------- /gpsdData.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python 2 | # Written by Dan Mandle http://dan.mandle.me September 2012 3 | # License: GPL 2.0 4 | 5 | import os 6 | from gps import * 7 | from time import * 8 | import time 9 | import threading 10 | 11 | gpsd = None #seting the global variable 12 | 13 | os.system('clear') #clear the terminal (optional) 14 | 15 | class GpsPoller(threading.Thread): 16 | def __init__(self): 17 | threading.Thread.__init__(self) 18 | global gpsd #bring it in scope 19 | gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info 20 | self.current_value = None 21 | self.running = True #setting the thread running to true 22 | 23 | def run(self): 24 | global gpsd 25 | while gpsp.running: 26 | gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer 27 | 28 | if __name__ == '__main__': 29 | gpsp = GpsPoller() # create the thread 30 | try: 31 | gpsp.start() # start it up 32 | while True: 33 | #It may take a second or two to get good data 34 | #print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc 35 | 36 | os.system('clear') 37 | 38 | print 39 | print ' GPS reading' 40 | print '----------------------------------------' 41 | print 'latitude ' , gpsd.fix.latitude 42 | print 'longitude ' , gpsd.fix.longitude 43 | print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time 44 | print 'altitude (m)' , gpsd.fix.altitude 45 | print 'eps ' , gpsd.fix.eps 46 | print 'epx ' , gpsd.fix.epx 47 | print 'epv ' , gpsd.fix.epv 48 | print 'ept ' , gpsd.fix.ept 49 | print 'speed (m/s) ' , gpsd.fix.speed 50 | print 'climb ' , gpsd.fix.climb 51 | print 'track ' , gpsd.fix.track 52 | print 'mode ' , gpsd.fix.mode 53 | print 54 | print 'sats ' , gpsd.satellites 55 | 56 | time.sleep(5) #set to whatever 57 | 58 | except (KeyboardInterrupt, SystemExit): #when you press ctrl+c 59 | print "\nKilling Thread..." 60 | gpsp.running = False 61 | gpsp.join() # wait for the thread to finish what it's doing 62 | print "Done.\nExiting." -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Python-NEO-6M-GPS-Raspberry-Pi 2 | Python script for the NEO-6M GPS module on the Raspberry Pi 3 | ## 1. Connecting Schema 4 | ![Image of Yaktocat](https://raspberrytips.nl/wp-content/uploads/2016/12/UBOLX-NEO-6M-RPI-600x274.png) 5 | ![Image of Yaktoc2at](https://www.raspberrypi-spy.co.uk/wp-content/uploads/2012/06/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated-2700x900.png) 6 | ![Image of Yaktoc2at2](./gps-neo-6m-board-schematic.png) 7 | ![Image of Yaktoc2at2](./00532_Raspberry_Pi_NEO-6M_GPS-Modul_-_Schaltplan.png) 8 | ## 2. Install the Dependencies 9 | * pip installed. 10 | ``` 11 | sudo apt-get install python-pip 12 | ``` 13 | * you will need pynmea2. 14 | ``` 15 | sudo pip install pynmea2 16 | ``` 17 | * You need the GPS software 18 | ``` 19 | sudo apt-get install gpsd gpsd-clients python-gps minicom 20 | ``` 21 | ## 3. Configurate the services 22 | * Serial port modify cmdline.txt: 23 | ``` 24 | sudo nano /boot/cmdline.txt 25 | ``` 26 | and replace all with the following lines: 27 | ``` 28 | dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles 29 | ``` 30 | * Change startup settings: 31 | ``` 32 | sudo nano /boot/config.txt 33 | ``` 34 | and at the end of the file add the following lines: 35 | ``` 36 | dtparam=spi=on 37 | dtoverlay=pi3-disable-bt 38 | core_freq=250 39 | enable_uart=1 40 | force_turbo=1 41 | init_uart_baud=9600 42 | ``` 43 | * reboot the system: 44 | ``` 45 | sudo reboot now 46 | ``` 47 | * Configure the module for the 9600 rate: 48 | ``` 49 | stty -F /dev/ttyAMA0 9600 50 | ``` 51 | * Connect AMA0 to the GPS Software 52 | First kill the process and add the device to gpsd tool 53 | ``` 54 | sudo killall gpsd 55 | sudo nano /etc/default/gpsd 56 | ``` 57 | Edit the file /etc/default/gpsd and add your serial port in DEVICES, like 58 | ``` 59 | DEVICES="/dev/ttyAMA0" 60 | ``` 61 | * Restart the Software 62 | ``` 63 | sudo systemctl enable gpsd.socket 64 | sudo systemctl start gpsd.socket 65 | sudo cgps -s 66 | ``` 67 | ## 4. Run the Example 68 | These instructions will get you a quick start with the script and please check before if you have the dependencies installed. Also connect the raspberry like the obove schemata. 69 | * Look if the terminal output of the sensor works 70 | ``` 71 | cat /dev/ttyAMA0 72 | ``` 73 | or use: 74 | ``` 75 | cgps -s 76 | ``` 77 | * Run the script 78 | ``` 79 | cd Python-NEO-6M-GPS-Raspberry-Pi 80 | sudo python Neo6mGPS.py 81 | ``` 82 | The above examples can take up too 10-20min to find a GPS signal for the first time. After this the gps module will be able to find the gps signal a lot faster. That mean please leave the script or the cat command running for a coupe of minutes. 83 | ## 5. Example source code 84 | ``` 85 | import serial 86 | import pynmea2 87 | def parseGPS(str): 88 | if str.find('GGA') > 0: 89 | msg = pynmea2.parse(str) 90 | print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: 91 | %s %s" % 92 | (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,m 93 | sg.altitude_units) 94 | serialPort = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) 95 | while True: 96 | str = serialPort.readline() 97 | parseGPS(str) 98 | 99 | ``` 100 | --------------------------------------------------------------------------------