I can't run this gps program in Thonny IDE. How come I can only run this gps program when I run it in the terminal without sudo? Is there a way to fix this? EDIT: The part without the print(gps) and the missing colon is a typo
import serial
import time
import string
import pynmea2
while True:
port=”/dev/ttyAMA0”
ser=serial.Serial(port, baudrate=9600, timeout=0.5)
dataout = pynmea2.NMEAStreamReader()
newdata=ser.readline()
if newdata[0:6] == “$GPRMC”
newmsg = pynmea2.prase(newdata)
lat = newmsg.latitude
lng = newmsg.longitude
gps = “Latitude= ” + str(lat) + “ and Longitude= ” + str(lng)
When I run it in Thonny IDE, it only says Run gps.py with nothing below.
EDIT: This code from @tlfong01 in link #1 seemed to do the trick.
import serial
import time
import string
import pynmea2
port="/dev/ttyAMA0"
ser=serial.Serial(port, baudrate=9600 , parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,)
while True:
dataout = pynmea2.NMEAStreamReader()
newdata=ser.readline()
if (newdata[0:6] == b"$GPRMC"):
newmsg=pynmea2.parse(newdata.decode("utf-8"))
lat=newmsg.latitude
lng=newmsg.longitude
gps = "Latitude=" + str(lat) + "and Longitude=" + str(lng)
print(gps)
python gps.py
– Ilian May 19 '21 at 09:27