Decoding Bytes from a UART

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
flyboyCW12
Posts: 3
Joined: Sat Jun 25, 2022 11:34 am

Decoding Bytes from a UART

Post by flyboyCW12 » Sat Jun 25, 2022 11:56 am

Hello,

I'm new to the forum and pretty new to MicroPython and coding in general. Still I spent most of my working life in the electronics industry and have specific experience in the embedded systems space.

I'm working on an implementation of a GPS/Wifi Beacon based on an ESP32 board and have found some excellent resources to leverage. Most specifically I am working on understanding the micropyGPS work - but, all in all, the learning curve is fairly steep!

I've got a GPS chip (taken from one of my fixed wing aircraft) which I therefore know works and hooked it up to UART2 on my ESP32 board.

This is an example of what I see...

b'\x00 \xfe'
b'\x00\xc0'
b'\x00\x8eNR\xfd\xbf, ,,,\xec\xd7\xff\xbf\x13\x90\x88:\xb9\xff\xff\xff\xff\xff\x92\x80\x1a\n'
b'4\xff\x02\x00,,,\xff\xff\xff\xff\xff\xff\xff\xbd\x0c\x04X*\xb7\xfd\x7f\xff\x96\x00%\x89\xa9\xff\xff\xff\xd7\xb5\x00\x00r,\xbd\x7f\xdb\x7f\x11\x00A,\xb1\xbd\xff\xff\xbd%\x0099,\xff\xff\xff\xd5\r\n'
b'HGP\xff\xff\xfd\xff\x96\x00\xbab\x92\xff\xff\x7f\xd7\xff\xbf\x02`7,\xae\xffkD\x00b\x92b'
b'\xff\xff\xff\xb5)\x00GLG\xf7\xff\xff$\x00\xea1\xfd\xff\xd7\xfd\xfb\xfd\xff\x0c\x04\xc5r\xad\xff'
b'\x00\x00\xfe'
b'\x00\xe0'

...when running this code:

from machine import UART

# Setup the connection to your GPS here
# This example uses UART 3 with RX on pin Y10
# Baudrate is 9600bps, with the standard 8 bits, 1 stop bit, no parity

uart = UART(2, baudrate = 9600, tx =17, rx = 16, bits = 8, parity = None, stop = 1)

# Basic UART --> terminal printer, use to test your GPS module
while True:
if uart.any():
buf = uart.readline()
# buf = buf.decode("utf-8")
print(buf)

Clearly what I'd like to be able to confirm is that this is a valid NMEA sentence from the GPS chip but for the life of me I can't figure out how to convert this string of bytes into ascii which I might recognise. Unicode errors and sytax errors seem to be my speciality ;)

I am sure I'm missing something here and would greatly appreciate some points to get me moving again.

All the Best

Harry

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Decoding Bytes from a UART

Post by Roberthh » Sat Jun 25, 2022 11:58 am

Either the baud rate or the polarity is wrong.

flyboyCW12
Posts: 3
Joined: Sat Jun 25, 2022 11:34 am

Re: Decoding Bytes from a UART

Post by flyboyCW12 » Sun Jul 10, 2022 9:38 am

Hi,

Just to close the loop the problem came down to the simple mistake of failing to implement a common ground between the GPS sensor supply and the ESP32 supply. My data inputs were basically floating around. One simple wire link and the data became readable as ASCII characters. A stupid mistake on my part.

Cheers and thanks for the response.

Harry

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Decoding Bytes from a UART

Post by jimmo » Mon Jul 11, 2022 12:30 am

flyboyCW12 wrote:
Sun Jul 10, 2022 9:38 am
common ground between the GPS sensor supply and the ESP32 supply. My data inputs were basically floating around.
Thanks for the follow-up... wish I'd thought of that to suggest :)

Post Reply