Я не могу прочитать данные с выводов RART Raspberry Pi UART. Это код Python, который я использовал:
import serial
import time
import string
import pynmea2
while True:
port="/dev/ttyAMA0"
ser=serial.Serial(port, baudrate=115200, timeout=0.5)
dataout = pynmea2.NMEAStreamReader()
newdata=ser.readline()
if newdata[0:6] == "$GPRMC":
newmsg=pynmea2.parse(newdata)
lat=newmsg.latitude
lng=newmsg.longitude
gps = "Latitude=" + str(lat) + "and Longitude=" + str(lng)
print(gps)
Когда я запускаю код, я получаю эту ошибку:
Traceback (most recent call last): File"/usr/lib/python3/distpackages/serial/serialposix.py", line 265, in openself.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) PermissionError: [Errno 13] Permission denied:'/dev/ttyAMA0' During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/pi/Desktop/sa.py", line 8, in <module> ser=serial.Serial(port, baudrate=115200, timeout=0.5) File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 240, in__init__
self.open() File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno13] could not open port /dev/ttyAMA0: [Errno 13] Permission denied:'/dev/ttyAMA0'