A test to read GPS connected to Edison UART using python.
The connection with UART is made by mraa, and the acquired value is processed by pynmea2.
import mraa
import serial
import pynmea2
#UART port specification
uart = mraa.Uart(0)
#Creation of Serial object. Baud rate is 9600bps
ser = serial.Serial(uart.getDevicePath(), 9600)
while 1:
#Parse line by line
msg = pynmea2.parse(ser.readline())
#Sentence processes GGA stuff
if msg.sentence_type == 'GGA': # Global Positioning System Fix Data
print {
'gps.number_of_satellites': msg.num_sats,
'gps.latitude': msg.latitude,
'gps.longitude': msg.longitude,
'gps.altitude': msg.altitude,
}
You can get something like this.
{
'gps.altitude': -12.8,
'gps.longitude': 139.77447469,
'gps.number_of_satellites': '11',
'gps.latitude': 35.700290937
}
As long as the circuit is connected, python + mraa + pynmea2 can handle it very easily. There are several sentences defined in NMEA, so it seems that you need to understand NMEA to use it correctly.
Recommended Posts