# Can pySerial be used to control the UART on PYNQ?

**URL:** <https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441>\
**Category:** Support\
**Created:** [September 6, 2019, 8:00am UTC](https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441 "2019-09-06T08:00:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NS\_Huang](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/ns_huang/32/151_2.png) [@NS\_Huang](https://discuss.pynq.io/u/NS_Huang)\
**Post date:** [September 6, 2019, 8:00am UTC](https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441/1 "2019-09-06T08:00:08Z")

</div>

Hi, dear PYNQ elites,

In PYNQ, there is UART (0 or 1) in the PS side. If the user use the UART on PYNQ to communicate with other board, it needs to have the UART driver code on the PYNQ. From the existing PYNQ doc and library code, I don’t find any python example code for UART control but GPIO and IIC etc.

However, I found the following library pySerial for UART control SW. As you know, can we install the pySerial package on the Linux on PYNQ for the UART control of PYNQ ?

Or user needs to write the UART driver code for the PYNQ.

> **[GitHub - pyserial/pyserial: Python serial port access library](https://github.com/pyserial/pyserial)**
>
> Python serial port access library. Contribute to pyserial/pyserial development by creating an account on GitHub.

Or where can user find the python example code for UART control on PYNQ.

Thank you  
All the best,

---

<div class="post-metadata">

**Author:** ![rock](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rock/32/32_2.png) [@rock](https://discuss.pynq.io/u/rock)\
**Post date:** [September 12, 2019, 4:44pm UTC](https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441/2 "2019-09-12T16:44:57Z")

</div>

Have you tried [PYNQ/uart.c at master · Xilinx/PYNQ · GitHub](https://github.com/Xilinx/PYNQ/blob/master/boards/sw_repo/pynqmb/src/uart.c)

You can try it out on ipython microblaze; I think I did some testing in the past - it worked. You can do some testing with the base overlay, where microblaze is controlling the uart.

---

<div class="post-metadata">

**Author:** ![NS\_Huang](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/ns_huang/32/151_2.png) [@NS\_Huang](https://discuss.pynq.io/u/NS_Huang)\
**Post date:** [September 13, 2019, 11:59am UTC](https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441/3 "2019-09-13T11:59:08Z")

</div>

Hi, Rock,

Thanks for the information.

Actually, we would like to use the uart on ARM CPU instead of microblaze on PYNQ in the original plan. Do you know if there has any python UART example on ARM CPU on PYNQ ?

All the best,

---

<div class="post-metadata">

**Author:** ![VicerExciser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/vicerexciser/32/1643_2.png) [@VicerExciser](https://discuss.pynq.io/u/VicerExciser)\
**Post date:** [October 29, 2020, 8:48pm UTC](https://discuss.pynq.io/t/can-pyserial-be-used-to-control-the-uart-on-pynq/441/4 "2020-10-29T20:48:57Z")

</div>

Yes, I’ve achieved this by using the `serial` Python package. When connected to the PYNQ’s USB HOST, your device should be visible at the OS-level on the board (e.g., as `/dev/ttyUSB0` ). Then you can write a script that initializes your UART/serial bus like so:

> ser = serial.Serial(’/dev/ttyUSB0’, baudrate=9600, timeout=0.5)

Data can then be sent & received using the methods:

> ser.flushInput()  
> ser.write(payload)  
> resp = ser.read(4)

If you are looking to establish UART communication for a device that is not connected to the USB HOST interface, though, you will need to go through the PL – easiest way to do this is using the MicroblazeLibrary class as a wrapper for the UART API implemented in ‘uart.c’.
