File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Simple GPS datalogging demonstration for use with a computer like Linux/desktop.
2
+ # This actually doesn't even use the GPS library and instead just reads raw
3
+ # NMEA sentences from the GPS unit and dumps them to a file.
4
+
5
+ import board
6
+ import busio
7
+ import serial # pyserial is required
8
+
9
+ # Path to the file to log GPS data. By default this will be appended to
10
+ # which means new lines are added at the end and all old data is kept.
11
+ # Change this path to point at the filename desired
12
+ LOG_FILE = 'gps.txt' # Example for writing to local file gps.txt
13
+
14
+ # File more for opening the log file. Mode 'ab' means append or add new lines
15
+ # to the end of the file rather than erasing it and starting over. If you'd
16
+ # like to erase the file and start clean each time use the value 'wb' instead.
17
+ LOG_MODE = 'ab'
18
+
19
+ # Create a serial connection for the GPS connection using default speed and
20
+ # a slightly higher timeout (GPS modules typically update once a second).
21
+ # Update the serial port name to match the serial connection for the GPS!
22
+ uart = serial .Serial ("/dev/ttyUSB0" , baudrate = 9600 , timeout = 3000 )
23
+
24
+ # Main loop just reads data from the GPS module and writes it back out to
25
+ # the output file while also printing to serial output.
26
+ with open (LOG_FILE , LOG_MODE ) as outfile :
27
+ while True :
28
+ sentence = uart .readline ()
29
+ print (str (sentence , 'ascii' ).strip ())
30
+ outfile .write (sentence )
31
+ outfile .flush ()
You can’t perform that action at this time.
0 commit comments