Last active
June 19, 2023 17:05
-
-
Save skittleson/0ac749a7a992fdaaf87006484f084f8e to your computer and use it in GitHub Desktop.
Get GPS data from usb device and print it to the screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install pynmea2 pyserial | |
import serial | |
import pynmea2 | |
ser = serial.Serial("COM4", baudrate=9600, timeout=1.0) | |
dataout = pynmea2.NMEAStreamReader() | |
while True: | |
newdata = ser.readline().decode("utf-8") | |
if newdata[0:6] == "$GPRMC": | |
newmsg = pynmea2.parse(newdata) | |
lat = newmsg.latitude | |
lng = newmsg.longitude | |
print(f'Latitude {lat} Longitude {lng}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GPS = require("gps"); | |
const { SerialPort, ReadlineParser } = require('serialport') | |
const gps = new GPS; | |
// Use a `\r\n` as a line terminator | |
const parser = new ReadlineParser({ | |
delimiter: '\n', | |
}) | |
const port = new SerialPort({ | |
path: '/dev/ttyACM0', | |
baudRate: 57600, | |
}) | |
port.pipe(parser) | |
port.on('open', () => console.log('Port open')) | |
parser.on('data', data => { | |
gps.update(data); | |
}); | |
port.write('ROBOT PLEASE RESPOND\n') | |
gps.on('data', parsed => { | |
console.log(parsed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment