====== Connecting Mervis IDE to Weintek HMI device using the ModbusTCP/RTU protocol ====== In this tutorial, we are going to demonstrate how to connect the Weintek iP series HMI device with Unipi controller running Mervis. The goal of this tutorial is to display temperature measured by the 1-Wire temperature sensor connected to Unipi on the HMI display and have a touch button on the display that will turn the relay output of the Unipi ON and OFF. ;;# Patron \\ Neuron \\ Gate \\ Unipi 1.1 \\ Axon ;;# Do you need to communicat over Ethernet? Our most recent news might be useful for you. Check out our new tutorial describing connection of a **[[en:sw:01-mervis:weintek-hmi-bacnet-mervis-hidden|Weintek HMI to Unipi PLC through BACnet]]**, using Mervis IDE development environment. Prerequisites: * Unipi Neuron controller with [[en:files:software:os-images:00-start|Mervis OS]] installed * [[https://www.unipi.technology/hmi-devices-c29|Weintek HMI device]] * [[https://www.unipi.technology/power-supplies-c15|24 V⎓ power supply]] * 3 ethernet connections - one for Unipi controller, one for HMI and one for your PC \\ In this tutorial, we have used: * [[https://www.unipi.technology/unipi-neuron-l503-p105|Unipi Neuron L503]] * [[https://www.unipi.technology/weintek-mt8051ip-p198|Weintek MT8051iP]] * [[https://www.unipi.technology/1-wire-temperature-sensor-p63?categoryId=3|1-Wire temperature sensor]] == Wiring of the test setup == {{:en:sw:01-mervis:infografika.png?direct&600|}} ===== Installation of software ===== For basic configuration of the Unipi controller and installation of Mervis on your computer, please follow [[en:sw:01-mervis:running-on-neuron-hidden|this guide]]. For configuration of the HMI we need to install the Weintek EasyBuilder Pro. You can download the version used in this tutorial [[files:software:tools:00-start#weintek_easybuilder_pro|here]], or you can download the latest version from the [[http://www.weintek.com/|manufacturer's website]]. The installation file is not signed by verified publisher, so you will be ask for confirmation. The rest of the installation is easy and you can confirm all the options by clicking on **Next**. ===== Configuration of the HMI ===== From Start menu on your PC, open the Easybuilder Pro. You will be greeted by the welcome screen, where you can open recent project, or create a new one. We will create a new project by clicking on the **New** button. {{ :en:hw:04-hmi:weintek_ip_series_01_selecting_new_project.png?direct |}} In the next dialog, you have to pick to correct model of the display you want to configure. We will pick the MT8051iP and then hit OK. {{ :en:hw:04-hmi:weintek_ip_series_02_selecting_device.png?direct |}} Next dialog is the **System properties**, where we will manage the connections to Modbus slaves or configuration of the Modbus master. We will get to this later, so for now just hit OK. {{ :en:hw:04-hmi:weintek_ip_series_03_confirm_system_properties.png?direct |}} Now you see the main window. On the top of the window, you have a list of panels called **Home**, **Project**, **Object**, etc. We will call this list a **Ribbon**. On the left side, you can see a list of **Windows**. Each window is a graphical representation of what can appear on the HMI display. On the center of the main window, you have a blank window canvas. The window is named WINDOW_010, which is the default window displayed on the device after reboot. {{ :en:hw:04-hmi:weintek_ip_series_04_main_window.png?direct |}} First, we will create some text object and place it onto the canvas. Click on the **Object** on the **Ribbon** and click on **A** in the section **Draw**. {{ :en:hw:04-hmi:weintek_ip_series_05_adding_text.png?direct |}} In the **New text** dialog, we can set all different kinds of parameters. We will fill the content and set the font size to 20 and hit **OK**. {{ :en:hw:04-hmi:weintek_ip_series_05_seting_text.png?direct |}} After clicking **OK** the dialog will close and you can place the text on the window. The result will look like this: {{ :en:hw:04-hmi:weintek_ip_series_06_placed_text.png?direct |}} The text object is static, which means the content cannot be dynamically changed e.g. from some variable or register. For displaying content of local HMI variable or Modbus register, we have to add numeric display box. Click on the **Object** panel on the **Ribbon** and then select **Numeric** in **Input** section. {{ :en:hw:04-hmi:weintek_ip_series_08_adding_numeric.png?direct |}} In the **New Numeric Object** dialog, we will set some description. The description acts as a comment - it will not be displayed anywhere on the HMI device. Since we want to display the temperature, we can uncheck the **Allow input**. This will disable the ability of setting the value from touch display. The **Read address** box is for mapping the **Numeric** object to some variable or register. Because we haven't set the communication with Unipi yet, we will leave the **Read address** box as is. Therefor the new numeric object will display the content of local word (LW) variable number 0. Don't bother with this, this is just for demonstration. {{ :en:hw:04-hmi:weintek_ip_series_09_setting_numeric.png?direct |}} The last thing what we will do, is to change the appearance. By default, the Easybuilder will display a nasty border around the object, which we don't want to. In the same dialog, click on the panel **Shape** and uncheck the value **Use shape** and then hit **OK**. {{ :en:hw:04-hmi:weintek_ip_series_10_removing_numeric_shape.png?direct |}} As with the text, you can place the new object on the window. The result can look like this.{{ :en:hw:04-hmi:weintek_ip_series_11_placed_numeric.png?direct |}} Now that we have some basic window settings, we can check, how it will look on the HMI device. The Easybuilder Pro makes it really easy, because you can simulate the project on your computer, without having the actual HMI device. Click on the **Project** on the **Ribbon** and you can see, that you have two buttons available: **Online simulation** and **Offline simulation**. Both of the buttons will compile the project and run it in local window, and you can interact with it as you would with the physical HMI device. The **Online simulation** will start the simulation and it will also start polling data from configured Modbus slaves, or start the Modbus server so the PLCs can fill the HMI with relevant data. The **Offline simulation** starts the simulation without this polling. Since we don't have any connection configured, we can start the **Offline simulation**. After clicking, the compilation of the project will appear and after few seconds, you will see the actual simulated project window. {{ :en:hw:04-hmi:weintek_ip_series_12_first_simulation.png?direct |}} So far we have created simple window, which displays a numeric value of some register. To make this tutorial little bit more versatile, let's learn, how to create a button, which - in the end - will operate relay output on our Unipi. To do this, we have to place new object onto the window canvas, called **Set bit**. On **Object** panel, click on the **Set bit**. {{ :en:hw:04-hmi:weintek_ip_series_13_adding_button.png?direct |}} In the **New Set Bit Object** dialog you can fill the comment. The comment will not be shown anywhere in the window, it is just for your better orientation in the project. The box **Write address** looks very similar to the **Read address** block we saw in the **New Numeric object**. But in this instance, we point the output value of the button (ON/OFF, TRUE/FALSE) to some **bit** variable. In numeric object, we pointed it to **word** variable. Since we still didn't configure connection to Unipi, we will leave it as is. What we will change is the **Attribute**. This attribute sets how the button will output the value. We will change it to **Momentary**, which will make the button behave as a momentary switch. When the button is pressed (and hold), it will set the **Write address** register to 1 and when it is released, it will set the register to 0. {{ :en:hw:04-hmi:weintek_ip_series_14_bit_object_configuration.png?direct |}} The last thing we will change is the button looks, or in Weintek terminology, **Shape**. Click on the **Shape** panel and change the picture of the button by clicking on the **Picture library**. {{ :en:hw:04-hmi:weintek_ip_series_15_picture_library.png?direct |}} In the **Picture library** dialog you can find all different kinds of button images and even have an option to upload your own. We will select the first, round one and then click **OK**. {{ :en:hw:04-hmi:weintek_ip_series_16_round_picture.png?direct |}} We are back in the **Shape** dialog and as a last thing, we will change the color of the button to light green and then hit **OK**. {{ :en:hw:04-hmi:weintek_ip_series_17_set_color.png?direct |}} Now we can place the button onto the window canvas. {{ :en:hw:04-hmi:weintek_ip_series_18_window_with_button.png?direct |}} And we can simulate the project by clicking on the **Project** on the **Ribbon** and then on **Offline simulation**. And you can try pressing the button. {{ :en:hw:04-hmi:weintek_ip_series_19_pressed_button.png?direct |}} Let's download the project into HMI device. First, we need to get its IP address. The device in default settings gets IP address from DHCP server nad you can find this information directly on the HMI device. On the touch screen, there is a left arrow icon at the bottom right corner. By clicking on it, a small menu will appear. Then click on the icon of page with (I) and there you can find the IP address. After acquiring the IP address, we can proceed with the actual download. On the **Ribbon** click on the **Project** and then click on **Download**. {{ :en:hw:04-hmi:weintek_ip_series_20_download.png?direct |}} The only operation you have to do in the **Download** dialog is filling the IP address. Then hit **Download**. The HMI device will reboot and start your project. The result should look the same as in the simulation. The temperature will be 0 and pressing the button does nothing. ===== Communication between HMI and Unipi===== So far we have fully functional HMI design and now we have to connect it to Unipi. But first, we need to discuss the data exchange options we have. The HMI device can communicate with Unipi via two different protocols: - ModbusTCP over ethernet - ModbusRTU over two wire RS485 In Modbus protocol, the communication is always initialized by the master (client) device. The slave (server) device responds to the commands issued by the master. Master is the one who reads data from slave, or writes data to slave. Since the Unipi and Weintek iP series HMI can act both as a master and slave, we have to decide which way to go. That depends on your application and overall logic of your system. In this tutorial, we will investigate both options and demonstrate the pros and cons. ==== Unipi as master, HMI as slave ==== This is the traditional data exchange method. PLC downloads data from Modbus slaves (Unipi extensions, energy meters,...), decides what to do and then uploads the data to the slaves. **Pros:** * Traditional way how to exchange data which will be probably a better fit for your current infrastructure **Cons:** * The HMI has to be configured in Mervis as a Modbus slave device with complicated parsing of data * The HMI doesn't have easy method to check, whether the connection to Unipi is running and the registers contain up-to-date data ==== HMI as master, Unipi as slave ==== In this setup, the data exchange between HMI and Unipi is initiated by the HMI device. The HMI reads the temperature from Unipi, which shares this information via its ModbusTCP Server register. **Pros:** * HMI can detect broken connection and act accordingly * Easier setup on the Mervis side **Cons:** * On RS485 connection only one device can act as a master. If the PLC is already a master, you have to use another RS485 connection to HMI For the rest of the tutorial, we will use this method. ===== Setting up the Unipi for sharing temperature and relay output ===== For the purposes of our demonstration, we need Unipi controller running Mervis. You can find all the necessary information in our [[en:sw:01-mervis|Mervis section]]. Next thing we need to configure is the temperature reading from 1-Wire temperature sensor. You can find it [[en:sw:01-mervis:attaching-1-wire-devices-hidden|here]] how to do so. In order to share the temperature over ModbusTCP, you need to configure ModbusTCP server channel. We have a tutorial ready for this as well: [[en:sw:01-mervis:setting-modbus-server-hidden]]. Now we need to clarify, what type of data we need to set in the Mervis ModbusTCP server. Modbus protocol knows only two types of data: 16 bit registers for numeric values and 1 bit "coils" for state values. The temperature in the Mervis is represented as a real number - 32 bit unsigned integer. To transfer this value via Modbus, we would need to split it into two 16 bit registers and put them together on the HMI side, which is out of the scope of this tutorial. But we can convert the real temperature value to roughly fit the 16 bit register. Let's assume we measure room temperature, where it can be in range of 0-40 °C, and we want precision at least to 0.1 °C. That means we need to cover values of 0-400. That can easilly fit into the 16 bit register we have. Let's take a look, how to achieve it in FB diagram: {{ :en:hw:04-hmi:weintek_ip_series_22_conversion_program.png?direct |}} On the input side, we have variable ''sensor_temperature'' which is the value of the 1-Wire sensor. On the output side we have variable ''modbus_temperature'' - that's the value exported by ModbusTCP server as holding register number 1. The actual temperature if 26.8125 °C. We multiply it by 10 in the ''MUL'' block to value 268.125. This value is type "real" and we need co convert it to integer to fit the holding register type. The block ''TO_UINT'' converts any value to integer, and if the input value is less then 0, it will output 0 - hence the name **to unsigned integer**. We cheated the measured values a bit, but for our purposes, it works OK. Now we can export this variable in ModbusTCP server. In Mervis, double click on the ModbusTCP server device. {{ :en:hw:04-hmi:weintek_ip_series_23_modbus_tcp_server.png?direct |}} In the center window, the list of registers will appear. The list is empty and we need to add register. Right click in the empty list and select **Add register**. {{ :en:hw:04-hmi:weintek_ip_series_24_add_register.png?direct |}} New register will appear. Change the **Simple Tranform** value to **Identity**. We already have the modbus_temperature variable in format we want. {{ :en:hw:04-hmi:weintek_ip_series_25_identity.png?direct |}} Leave the **Function** to **Holding Register**. Click on the **n/a** under the **Mapped Variable** and start typing the **modbus_temperature**. The variable should appear in the list and you can select it by click on its full name. {{ :en:hw:04-hmi:weintek_ip_series_26_mapped_variable.png?direct |}} Now we need to add Modbus "coil" to operate relay output. At the bottom of the device panel, there is list panel named **Digitals**. Click on it. {{ :en:hw:04-hmi:weintek_ip_series_27_digital_coil.png?direct |}} The blank list of digital registers will appear. Right click on the free space and then click on **Add coil**. {{ :en:hw:04-hmi:weintek_ip_series_28_add_coil.png?direct |}} Double click on the **n/a** under the **Mapped Variable** and type **RO.2_01**. If you don't have relay output 2.1 on your unit, you can type DO.1_01. Select the found variable in the list. {{ :en:hw:04-hmi:weintek_ip_series_29_mapped_variable.png?direct |}} Deploy the solution and start the Unipi controller in **Full mode**. ===== Setting the HMI to read data from Mervis ===== Now we have everything prepared on the Mervis side and we can configure the PLC in the HMI. On the **Ribbon** click on the **Home** and then on **System parameters**. {{ :en:hw:04-hmi:weintek_ip_series_30_system_properties.png?direct |}} On **System parameters** dialog, click on the **New...**. {{ :en:hw:04-hmi:weintek_ip_series_31_new_device.png?direct |}} Change the **Name** into something descriptive and click on the **Device type** option. {{ :en:hw:04-hmi:weintek_ip_series_31_new_modbus_device.png?direct |}} From the list of devices select **Modbus IDA** and from the sublist select **MODBUS TCP/IP** and confirm **OK** {{ :en:hw:04-hmi:weintek_ip_series_32_device_properties.png?direct |}} In the **IP** box, click on **Settings...**. {{ :en:hw:04-hmi:weintek_ip_series_33_ethernet_settings.png?direct |}} In the dialog **IP address settings** set the parameters that you have setted in the ModbusTCP server settings in Mervis. Confirm all the dialogs by clicking on **OK** until you will see the main window. {{ :en:hw:04-hmi:weintek_ip_series_34_ip_address_settings.png?direct |}} Now that we have the connection configured, we need to point the **Numeric** and **Set bit** objects to the correct devices and registers. Double click on the temperature **Numeric** object. In the **Numeric Object's Properties** dialog, select the Unipi controller in the **Device** drop down menu. {{ :en:hw:04-hmi:weintek_ip_series_36_select_the_plc.png?direct |}} Select the **Address** to **4x** which is a designation of holding registers and leave the address number to 1 - this is the number of the register in Mervis. {{ :en:hw:04-hmi:weintek_ip_series_37_4x_address_type.png?direct |}} Now we can run the **Online simulation** by clicking on the **Project** tab on the **Ribbon** and then clicking on the **Online simulation**. And if everything is OK, you should see similar window. {{ :en:hw:04-hmi:weintek_ip_series_39_online_with_wrong_temperature.png?direct |}} You can see the number 291, which is the converted number. But we want to display it in 29.1 format. To achieve this, we have to change the format of the numeric object. So exit from the simulation and again double click on the temperature's numeric object. In the **Numeric Object's Properties** select the **Format** panel. On the panel, change the **Left of decimal Pt.** to **2** and **Right of decimal Pt.** to **1** and confirm by clicking **OK**. {{ :en:hw:04-hmi:weintek_ip_series_40_temperature_format.png?direct |}} Run the **Online simulation** again and the temperature should look OK {{ :en:hw:04-hmi:weintek_ip_series_41_correct_temperature_format.png?direct |}} The last missing step is the address on the button. Double click the button and on the **Set Bit Object's Properties** change the **Write address** device to the Unipi controller, **Address** to **0x** which is a designation of "coil" and the coil number leave at **1**. {{ :en:hw:04-hmi:weintek_ip_series_42_set_bit_attribute.png?direct |}} Run the **Online simulation** and try pressing the button. If you set it to relay output in Mervis, you should hear the clicking sound of the relay. If you set it to digital output, the LED on the controller should be turning on and off. If everything seems to be OK, you can download the project into the HMI device. ===== Downloads ===== * {{ :en:sw:01-mervis:weintek_mt8051ip_testing_easybuilder.zip |EasyBuilder project files}} * {{ :en:sw:01-mervis:weintek_mt8051ip_testing_mervis.zip |Mervis project files}} * [[files:software:tools:00-start#weintek_easybuilder_pro|Weintek EasyBuilder Pro softwar]]e * {{ :en:sw:01-mervis:ebpro_manual.pdf |Weintek EasyBuilder Pro complete manual}} * [[https://www.unipi.technology/shop/product/download?fileId=404|Weintek MT8051iP datasheet]]