UART receive MAVLink messages micropython

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
airborne
Posts: 2
Joined: Fri Jun 30, 2017 2:59 pm

UART receive MAVLink messages micropython

Post by airborne » Fri Jun 30, 2017 3:35 pm

Hello,
As the title says I'm trying to read MAVLink messages using Micropython.
I know the length of the message, so I was thinking of using uart.read(LENGTH_OF_MESSAGE) - but that doesn't ensure I'm reading from the start of a message. Is there a way to specify start and stop bytes for UART read using Micropython? If I can't implement this in MicroPython, coding in C may be easier because headers for these messages can be auto-generated. However where the actual code for reading from UART using C is buried is beyond me. I've taken a look at files uart.c, uart.h and stream.c.

I've also read through /viewtopic.php?t=2848 and didn't find anything that helpful for me. Any ideas on how to proceed would be greatly appreciated.

Thanks!

Online
User avatar
dhylands
Posts: 3152
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: UART receive MAVLink messages micropython

Post by dhylands » Sat Jul 01, 2017 7:53 pm

I highly recommend that read one character at a time and build up the packet in memory. Doing multi-byte reads will cause all types of issues if a character ever gets dropped, or an extra one gets inserted.

For example, I wrote some code for sending/receiving packets to bioloid servos.

This is the code that processes a single byte from the UART:
https://github.com/dhylands/bioloid3/bl ... et.py#L191

This is an example of where it gets called:
https://github.com/dhylands/bioloid3/bl ... er.py#L135

I have low-level routines which work over USB:
https://github.com/dhylands/bioloid3/bl ... sb_port.py

or over a UART:
https://github.com/dhylands/bioloid3/bl ... rt_port.py

airborne
Posts: 2
Joined: Fri Jun 30, 2017 2:59 pm

Re: UART receive MAVLink messages micropython

Post by airborne » Sat Jul 01, 2017 9:42 pm

Thanks for the tips Dave. I'll look through what you just posted and give that a try!

Post Reply