# Will print NMEA sentences received from the GPS, great for testing connection # Uses the GPS to send some commands, then reads directly from the GPS import time import serial import board import busio import adafruit_gps timestr = time.strftime("%Y%m%d-%H%M%S") # Create a serial connection for the GPS connection using default speed and uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3000) # Create a GPS module instance. gps = adafruit_gps.GPS(uart) # Use UART/pyserial # Turn on the basic GGA and RMC info (what you typically want) gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") # Set update rate to twice a second (2hz, 500ms delay): gps.send_command(b'PMTK220,500') # Main loop runs forever printing data as it comes in timestamp = time.monotonic() file = open("/home/pi/projects/mqp/logs/gps_log_" + timestr + ".txt","w") while True: data = gps.read(32) # read up to 32 bytes # print(data) # this is a bytearray type if data is not None: # convert bytearray to string data_string = "".join([chr(b) for b in data]) print(data_string, end="") file.write(data_string) file.flush() """ if data is not None: # convert bytearray to string data_string = "".join([chr(b) for b in data]) print(data_string, end="") if time.monotonic() - timestamp > 5: # every 5 seconds... gps.send_command(b"PMTK605") # request firmware version timestamp = time.monotonic() ""”