Adafruit has a very good explanation about GPS interfacing. You may follow that tutorial or continue here.
To view, the available USB to TTL converter devices use the following command
ls /dev/ttyUSB*
If you had installed pyserial then you may list all your available COM ports using this command via python
python -m serial.tools.list_ports
Pyserial short Intro is a good place to get started with PySerial Library. One thing to remember while coding in Raspberry Pi 3 model is to use the naming convention difference from PI 2 model
port = "/dev/ttyAMA0" # Raspberry Pi 2 #port = "/dev/ttyS0" # Raspberry Pi 3
Deeper detail about serial communication as well as GPS string parsing code is available at the python-example website. From that link, we used this code to run and parse our GPS data
import serial
port = "/dev/ttyAMA0" # Raspberry Pi 2
#port = "/dev/ttyS0" # Raspberry Pi 3
def parseGPS(data):
# print "raw:", data
if data[0:6] == "$GPGGA":
s = data.split(",")
if s[7] == '0':
print "no satellite data available"
return
time = s[1][0:2] + ":" + s[1][2:4] + ":" + s[1][4:6]
lat = decode(s[2])
dirLat = s[3]
lon = decode(s[4])
dirLon = s[5]
alt = s[9] + " m"
sat = s[7]
print "Time(UTC): %s-- Latitude: %s(%s)-- Longitude:%s(%s)\
-- Altitute:%s--(%s satellites)" %(time, lat, dirLat, lon, dirLon, alt, sat)
def decode(coord):
# DDDMM.MMMMM -> DD deg MM.MMMMM min
v = coord.split(".")
head = v[0]
tail = v[1]
deg = head[0:-2]
min = head[-2:]
return deg + " deg " + min + "." + tail + " min"
ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)
while True:
data = ser.readline()
parseGPS(data)
To reboot raspberry PI
sudo shutdown -r now
Install minicom terminal to view the available data from serial port
sudo apt-get install minicom
The use this command to run minicom
minicom -b 9600 -o -D /dev/ttyUSB0
This article explains the above-mentioned minicom installation process.
To Exit from minicom: click Ctrl- A, Z then X.
Screen Serial Terminal
Minicom has a very bad user interface. Next best Option you have is “Screen Serial Consol”. You may install screen console using this command
sudo apt-get install screen
to run screen console use this command
sudo screen /dev/ttyUSB0 9600
To exit from screen console you can press
-
Ctrl + A then Ctrl + D . Doing this will detach you from the screen session which you can later resume by doing screen -r .
Cutecom Serial Monitor
Cutecom is a GUI based serial monitor. You can install this by typing
sudo apt-get install cutecom lxterminal -e 'cutecom'
It shows output like this
