Hex message with UART

Discussion related to "under the hood" OpenMV topics.
doodah
Posts: 11
Joined: Wed Jan 30, 2019 10:15 pm

Hex message with UART

Postby doodah » Thu Oct 10, 2019 5:50 pm

Hi! (again...)

I've looked around the internet a good bit, and can't seem to figure out the right way to send a Hex message to another devices over UART. The code below is where I'm at, with no success. Any suggestions?

Code: Select all


uart = UART(3, 19200)
message = b'\xaa\x00\x01\xBE\x00\x01\x00\x01\xC1'
uart.write(message)

Thanks!
User avatar
kwagyeman
Posts: 3335
Joined: Sun May 24, 2015 2:10 pm

Re: Hex message with UART

Postby kwagyeman » Thu Oct 10, 2019 5:58 pm

This is a pure python question... Use the binascii module: http://docs.micropython.org/en/latest/l ... t=binascii

uart.write(ubinascii.hexlify(data))
Nyamekye,
doodah
Posts: 11
Joined: Wed Jan 30, 2019 10:15 pm

Re: Hex message with UART

Postby doodah » Fri Oct 11, 2019 10:29 am

Thanks for the tip! This is what ended up working for me:

Code: Select all

message = 'AA0001BE00010001C1'
uart.write(ubinascii.unhexlify(message))

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests