From fcffc5ed8fb2bae3362c5da5b1a6c4111c2289e5 Mon Sep 17 00:00:00 2001 From: fanta Date: Wed, 4 Jun 2025 19:48:42 +0200 Subject: [PATCH] initial commit --- gpsreader.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 gpsreader.py diff --git a/gpsreader.py b/gpsreader.py new file mode 100644 index 0000000..52c589e --- /dev/null +++ b/gpsreader.py @@ -0,0 +1,38 @@ +# https://56k.es/fanta/utilizando-un-modulo-gps-usb-barato-en-gnulinux/ +# apt install python3-nmea2 python3-serial +# NMEA 0183 PROTOCOL: https://www.serialmon.com/protocols/nmea0183.shtml +# ('Timestamp', 'timestamp', timestamp), +# ('Latitude', 'lat'), +# ('Latitude Direction', 'lat_dir'), +# ('Longitude', 'lon'), +# ('Longitude Direction', 'lon_dir'), +# ('GPS Quality Indicator', 'gps_qual', int), +# ('Number of Satellites in use', 'num_sats'), +# ('Horizontal Dilution of Precision', 'horizontal_dil'), +# ('Antenna Alt above sea level (mean)', 'altitude', float), +# ('Units of altitude (meters)', 'altitude_units'), +# ('Geoidal Separation', 'geo_sep'), +# ('Units of Geoidal Separation (meters)', 'geo_sep_units'), +# ('Age of Differential GPS Data (secs)', 'age_gps_data'), +# ('Differential Reference Station ID', 'ref_station_id'), + +import io +import pynmea2 +import serial + +ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5.0) +sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser)) + +while 1: + try: + line = sio.readline() + msg = pynmea2.parse(line) + if msg.talker == "GP" and msg.sentence_type == "GGA": + print("[", msg.timestamp, "] [ Satelites:", msg.num_sats, "] - Lat:", msg.lat, "Lon:", msg.lon, "Alt:", msg.altitude) + + except serial.SerialException as e: + print('Device error: {}'.format(e)) + break + except pynmea2.ParseError as e: + print('Parse error: {}'.format(e)) + continue