# Reading UART Values In Sequence One Byte At A Time

**URL:** <https://forums.openmv.io/t/reading-uart-values-in-sequence-one-byte-at-a-time/8108>\
**Category:** OpenMV Boards\
**Created:** [March 19, 2023, 9:25am UTC](https://forums.openmv.io/t/reading-uart-values-in-sequence-one-byte-at-a-time/8108 "2023-03-19T09:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomastseng0830](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@thomastseng0830](https://forums.openmv.io/u/thomastseng0830)\
**Post date:** [March 19, 2023, 9:25am UTC](https://forums.openmv.io/t/reading-uart-values-in-sequence-one-byte-at-a-time/8108/1 "2023-03-19T09:25:03Z")

</div>

Hello,

I am trying to get an OpenMV H7 Plus board to read values off of the LD06 lidar. Since the lidar can only communicate with the OpenMV H7 Plus board through UART, I followed the instructions of the documentation and connected the lidar to the P4 and P5 pins of the OpenMV H7 Plus board. While I am able to read the correct values off of the LD06 lidar, I am not reading all of the data that I expected. More specifically, I am expecting that the lidar writes data into a buffer, and the OpenMV H7 Plus reads data off of the buffer one byte at a time (the buffer would be flushed under certain conditions). However, the OpenMV H7 Plus seems to be flushing the buffer after reading one byte of data every time `serial.read(1)` is called. I have written the same code (but using CPython) on a Raspberry Pi Zero 2 and was able to read the values one byte at a time in sequence as I expected. Since being able to read all the data and having all the data in sequence are important for my project, please provide any possible solutions to the problem. My code is as follows.

```auto
from pyb import UART

serial = UART(3)
serial.init(baudrate=230400, bits=8, parity=None, stop=1)

while True:
      if serial.any():
          read_byte = serial.read(1)
      else:
          continue
      print(read_byte)

```

Thank you!

Thomas

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [March 20, 2023, 10:03pm UTC](https://forums.openmv.io/t/reading-uart-values-in-sequence-one-byte-at-a-time/8108/2 "2023-03-20T22:03:16Z")

</div>

Hi, you might want to specify `timeout` and timeout\_char in the arguments of the serial port init. [class UART – duplex serial communication bus — MicroPython 1.19 documentation](https://docs.openmv.io/library/pyb.UART.html#pyb.UART.init) The default arguments shipping with MicroPython kinda make the serial port hard to use.

Anyway, I’m able to receive single characters with this script… and I don’t get any character drops.

Not sure how to help you debug. This works:

```auto
from pyb import UART
import time

serial = UART(3)
serial.init(baudrate=230400, bits=8, parity=None, stop=1)

while True:
      if serial.any():
          read_byte = serial.read(1)
      else:
          time.sleep(5)
          continue
      print(read_byte)

```

If I send 10 chars between the read then I get all bytes as expected.
