UART and end of line

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
161616harvard
Posts: 5
Joined: Fri Feb 12, 2021 7:33 pm

UART and end of line

Post by 161616harvard » Fri Feb 12, 2021 7:50 pm

Hello,

I'm trying to read 40 bytes from uart.readline() in micropython. However the reading stops when it encounters \x00.
Example.
"\xff\xff\xff\xff\x01\x00\x05\x07\x02\x44\x45\x41\"

uart.readline() returns b'\xff\xff\xff\xff\x01'

Can someone shed a light into this? Why does it convert to ascii and How can I read the 0 byte and the rest?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: UART and end of line

Post by kevinkk525 » Fri Feb 12, 2021 7:59 pm

If you are trying to read exactly 40 bytes, why are you using uart.readline()? You should be using uart.read(40)
But even then it might return less bytes if it reads faster than the other end sends bytes.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

161616harvard
Posts: 5
Joined: Fri Feb 12, 2021 7:33 pm

Re: UART and end of line

Post by 161616harvard » Fri Feb 12, 2021 8:12 pm

I added at the end he byte 0x0A for end of line, but I could use the uart.read(40)

I still have the same problem with \x00 byte since the reading stops there. Is there a solution to that?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: UART and end of line

Post by kevinkk525 » Fri Feb 12, 2021 8:34 pm

What hardware are you using?
if you use uart.readline() maybe it stops because it considers \x00 the end of a line? i don't know. I only use read()
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply