Skip to content

Commit ee5c403

Browse files
committed
the feather examples is pretty involved, its easier to just make a new example for computer/linux logging
1 parent 72abd3d commit ee5c403

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/computer_datalogging.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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()

0 commit comments

Comments
 (0)