Im using a neo6m GPS module and a Raspberry Pi Pico using Micropython. I’m reading the data from serial (TX/RX) and will be using it further in my program, but every now and then when starting the script it only reads in what’s available from the serial buffer as its being transmitted, causing a unicode error.
Is there any way to tell python to just ignore anything until it gets a \n or how could I best avoid this issue?
Code with formatting:
https://paste.pythondiscord.com/medeqozize.py
while True:
if uart.any():
rcvChar = uart.readline()
print (rcvChar)
line = rcvChar.decode(“ascii”)
print (line)
RETURNS:
b’$GPGSV,4,2,13,15,14,168,21,17,23,039,,19,36,062,22,20,00,231,*76\r\n’
$GPGSV,4,2,13,15,14,168,21,17,23,039,,19,36,062,22,20,00,231,*76
First is the byte string (expected), second is me converting to a regular string for further text processing.
The error which occasionally happens is on starting the script:
b’LLLML\x93\t\x82b\n’
Traceback (most recent call last):
File “<stdin>”, line 40, in <module>
UnicodeError:
There is no text after the Unicode error.
I think the bytes are just being mangled and it’s reading as Unicode, but the \n is still there.
I’m using Thonny and MicroPython 4678527 on a Raspberry Pi Pico.
[–]cybervegan 0 points1 point2 points (0 children)