How to contact uart in pynq‘s ardinuo or PMOD interface?

Hello, I want to use uart in pynq, it is okey to use uart in rpi interface, but how could we use it in ardunio or pmod?

1 Like

For the Arduino interface, you can use the MicroblazeLibrary class to create a wrapper object in Python that exposes the functions implemented in the PYNQ UART API (in ‘uart.c’). Here’s a very basic example of its usage:

from pynq import Overlay
from pynq.lib import MicroblazeLibrary

UART_RXD = 0 ## Arduino pin 0 is RXD
UART_TXD = 1 ## Arduino pin 1 is TXD

base = Overlay(‘base.bit’)
lib = MicroblazeLibrary(base.iop_arduino, [‘uart’])
uart = lib.uart_open(UART_TXD, UART_RXD)

read_command = [0xDE, 0xAD, 0xBE, 0xEF]
uart.write(read_command, len(read_command)) ## Write an iterable list of bytes

response = [0x00] * 4
uart.read(response, 4) ## Request a 4-byte response

uart.close()

I don’t believe either of the two Pmod PYNQ Microblaze IOPs have an AXI controller for UART, so Pmod UART may not be supported.

1 Like

Continuing the discussion from How to contact uart in pynq‘s ardinuo or PMOD interface?:

Hello all,

Im working with the uart of the iop_arduino(using pynq-z2). I currently have communication but seems like the uart buffer is limited to 16. Is there anyway to expand that? I need the buffer to be very large as to communicate with an HMI using Modbus.

code example:
from pynq.overlays.base import BaseOverlay
from pynq.lib import MicroblazeLibrary
import time

ol = BaseOverlay(“base.bit”)

UART_RXD = 0 ## Arduino pin 0
UART_TXD = 1 ## Arduino pin 1

uart = lib.uart_open(UART_TXD, UART_RXD)

send_buff = [x for x in range(21)]

while True:
uart.write(send_buff,len(send_buff)) ## Write an iterable list of bytes
time.sleep(.3)

Current output: