UART port (TX, RX) communication between Uni Pi 1.1 and Arduino Uno

  • Hello all,

    I'm trying to connect a device with Uni Pi via Uart port (TX, RX).
    I want to get information in Mervis from Arduino (some values from EC an pH sensors).
    I own Unipi 1.1 hardware, use Mervis 2.3 and the protocol wanted is serial communication between Unipi 1.1 as the slave and Arduino Uno master.

    I'm using a RJ11 connector from UART port on UniPi 1.1 to Arduino Uno:

    • UART port GND --> Arduino GND pin
    • UART port Rx --> Arduino Tx (pin 1)
    • UART port Tx --> Arduino Rx (pin 0)

    I've tried to open the port using:

    def := 'serial:6:9600,8,N,1';
      handle := io.openport(def);
      if handle >= 0 then
      state := 1;

    The state is updated to value "1" and then to value "2" after waiting for change of input value or timeout expiry after last values transmission - on case "1".
    But in case "2" I'm getting some port statuses like 31/53/77 after attempting to open the port:

    if io.getportstatus(handle) = 0 then (* OperationStatus_Ok ) ( spojeni navazano *)

    I tried different ports, with baud rate 9600 and second time with 115200 but I received the following errors:

    • on port 1: OperationStatus_Empty = 31
    • on ports 0, 2-9 and 20 - unknown error 77 (it's not in the list with possible return values)
    • on ports 10-19 - OperationStatus_FileNotFound = 53.

    Could you please advise on:

    • how to open that port / connect the serial port
    • what alternative do I have to make this communication between Arduino Uno and Uni Pi 1.1 to work
    • what is OpenPort?

  • administrators

    Hi Sabina,

    The best way to communicate between SW Mervis and third party devices is to implement the Modbus protocol on these devices. Subsequent operation and modifications are simpler and faster. Another great advantage is that this protocol basically allows you to operate multiple slave devices on one serial line.

    In this case, Openport is a functional block that takes care of opening the port, ie its reservation within the system.

    In the input string (def) for FB io.openport it is necessary to enter for UART port 1: "def: = 'serial: 1: 9600,8, N, 1';". I also enclose a tested code example in ST for Unipi 1.1.

Log in to reply