First project with Unipi 1.1/Lite

Every initial startup guide includes blinking LEDs or switching relays, and this tutorial is not an exception. Using this guide, we will create the simplest project possible with the intent to switch relay in 5s interval.

Unipi 1.1

This project includes all basic configurations needed to create the core of a Mervis IDE project and to deploy it to Unipi 1.1/1.1 Lite controller. All following tutorials use this one as their cornerstone, with the relay switching being the last chapter, using a FUPLA block program.

Prerequisites

  1. MicroSD card for the PLC
  2. MicroSD→SD adapter or a microSD card reader with USB connector
  3. Downloaded archive with Mervis OS for Unipi 1.1/Lite
  4. Computer with Mervis IDE installed.

For this guide it is NECESSARY to:

  1. Plug in the power supply and wait for at least a minute until the PLC's OS boots up.

In Mervis, a single project (eg. a set of configurations, programs and HMI interfaces) is known as a Solution. To create a new solution click on File → New solution (Ctrl+N), or click on the icon on the upper ribbon.

In the New solution dialogue window you need to enter the solution's name and the location it will be saved into. Fill both fields as required and confirm by clicking on OK.

The second thing you need to specify when creating a solution is mode selection. Modes determine Mervis IDE's behaviour during its use; Simple Mode pre-defines the core of the solution, eg. defines the basic programs, generates variable mappings etc. The downside is you can use only the Function Block Diagram (FBD) programming method in this mode. Simple Mode is thus suitable, especially for beginners. More experienced users should opt for the Full Mode. It is not possible to switch between the modes. Full Mode does not do the initial creation of the project skeleton and the entire basic configuration is up to you.

That said, it might be convenient (with the exception of some special cases) to create the solution's core automatically in Simple Mode and only then to switch to Full Mode.

Next step in creating a Solution is to connect to the running Unipi controller. In the Left panel on Solution tab, right click on the System and then click on the Add Controller.

The Find PLC dialogue will appear, in which we can specify, how the Mervis IDE should connect to the controller. If the PLC is in the same LAN network, you can use the UDP Broadcast and then click on Next.

Next window will show a progress bar as the Mervis IDE is looking for controllers on all network cards your computer has.

After the searching is finished, you will be presented with the list of detected PLCs. The target controller has its name displayed in the Platform tab. This tutorial used Neuron L503 controller - in your case, choose whatever controller you are using and click on Next.

In some cases, you will see a red triangle next to the Runtime version. This means the runtime is older than the IDE expects. To fix this problem, follow the Updating runtime (RT) tutorial.

If you see a small skull next to the Runtime version, the controller's operating system is outdated and you need to upload a current version of Mervis OS. The guide for uploading Mervis OS for Axon and Neuron & 1.1/Lite

The last dialogue of the controller attaching process asks you about configuration download. The configuration holds basic settings of the Unipi controller, such as IP address, usernames and passwords, connections to Mervis DB and Mervis Proxy and so on. We always recommend downloading the configuration during the initial attachment.

The controller has now connected; in the left panel in Solution a new PLC will appear. Double-click on it. In the main panel a PLC tab will be displayed and the PLCs properties will appear in the Properties panel.

Securing the PLC users:

WARNING: If the login info remains at default values, it may result in unauthorized personnel gaining access to the controller. This may cause unauthorized modifications of the system, leading to stoppage or limitation of the controlled technology. In the worst-case unauthorized access can cause damage to the technology, or even endanger maintenance personnel at the installation site.

  1. Create and remember your unique passwords and logins
  2. Find user definition section in the PLC properties
  3. Enter your login info
  4. It is important to not only change all passwords, but also their logins
  5. Leave the PLC connection parameters unchanged
  6. Now upload the configuration into the controller - follow this guide.
  7. After uploading the configuration, look for the PLC Connection Parameters, change the login (Engineering) entered in the previous step and save the solution
  8. If you leave PLC Connection Parameters unchanged, Mervis IDE will be unable to connect to the PLC
  9. Your PLC is now secured against unauthorized access

“Engineering” user has full access to all PLC configurations including changes in the control program, HW settings etc.


“Full control” user has access only to the control program variables and can read from them or write into them. However, this user cannot change configurations or the control program itself.


“Read-only” user is able only to read from the control program variables.

Secured connection with the PLC:
Secure connection has been introduced in the Mervis IDE v2.3.0.

  1. Look for SSCP Parameters in the PLC properties (network settings section)
  2. Set Enable SSL Server to TRUE
  3. upload the configuration into the controller. Follow this guide.
  4. With the configuration uploaded, look for Connection Parameters, change the TCP port to 12347 and set Enable SSL to TRUE
  5. Any connection between Mervis IDE and your PLC will be now secured.

In Mervis IDE you now have Unipi 1.1/Lite attached. Construction-wise, Unipi controllers consist of a computing module (Raspberry Pi in our case) and a circuit board with inputs and outputs. The board communicates with the computer using Modbus TCP and I2C. This is the reason why you need to set up two communication channels to control Unipi 1.1/1.1 Lite boards. The first channel is for controlling analog and digital I/Os via Modbus TCP protocol while the I2C channel controls relay outputs.

Add two communication channels to the PLC. TO add a channel right-click on the PLC name and then click on Add Channel. Repeat for the second channel.

Two channels will appear below the PLC item.

If you click on the first channel, its properties will appear in the right panel. The first item determines the channel's name; we recommend to give channels descriptive names - in this case, I2C will do.

Click on no protocol and select PlatformIO from the list. By doing so more options will appear - all you need to do here is to make sure the link protocol is set to I2C.

The first channel for relay outputs is already set.

Now click on the second channel you created and give it an appropriate name. As the channel will communicate via Modbus TCP, we will simply name it ModbusTCP.

Then again click on no protocol and set the protocol to Modbus. More options will be displayed - again, just make sure the link protocol is set to TCP.

With both channels configured we can now move to add individual devices. These device definitions are different between Unipi 1.1 and Unipi 1.1 Lite, making the correct selection of definition necessary.

I2C

In the left panel right-click on the I2C channel. Select Add Library Device from the context menu.

In the Add Library Device dialogue window you will see a list of devices. Find and expand the Unipi (v1.1) folder and move to the I2C subfolder. Select the suitable device definition accordingly (eg. Unipi1_Relays for Unipi 1.1 and Unipi1Lite_Relay for Unipi 1.1 Lite). If you have the definition selected, click on the arrow icon to add the controller into the list of the selected device. After that, you need only to confirm by clicking on OK.

ModbusTCP

In the left panel right-click on the ModbusTCP channel. Select Add Library Device in the context menu.

In the Add Library Device dialogue window a list of various devices will be displayed. Expand the Unipi technology folder and select the required definition depending on if you have Unipi 1.1 (Unipi 1 AO/DI/CNT) or Unipi 1.1 Lite (Unipi 1 Lite DI/CNT).

With the definition selected click on the arrow icon to add the controller into the list of selected devices. After that, you need only to confirm by clicking on OK.

The new device will appear below the corresponding I2C / Modbus TCP channel.

The next step is the configuration. This part is important especially if you are new to using PLCs with extension modules that have been used in Mervis IDE. These devices can store their last configuration that is independent of deployed solutions and might unexpectedly affect the PLC's function. However, you don't need to worry - if you did not select Download configuration in the previous steps you can upload the default configuration in Mervis IDE. Just make sure users, passwords and network settings (DHCP enabled as standard) are configured properly. Incorrect network settings or wrong login data would prevent you from connecting to the PLC and you would have to start all over again by uploading a clean Mervis OS into your PLC and the SD card. The Updating a runtime configuration tutorial will guide you through this process, including the process of uploading the configuration into Unipi controllers.

As you created the solution in Simple Mode, you do not have access to some Mervis IDE functions such as history logs. However, Simple Mode guarantees that all data point created from this moment onwards will have automatically generated global variables including definitions of input/output devices specified in the previous steps. Another advantage is the automatic creation of the main.program.fbd and its assignment to the PLC's task.

With everything required configured, you can switch the solution to Full Mode. Right-click on Solution Name (first tab) in the Solution panel in left menu. In the context menu click on Switch to Full Mode.

A warning will tell you the action is irreversible. Confirm by OK to continue.

The result is you now have access to other functions. The most visible change occurred in the left panel - at its bottom, the History log item appeared. Executable Projects now also displays Globals folder containing generated.Mixed.st file. This file contains variable definitions, in our case automatically generated by the Simple Mode. Don't delete, move or edit this file, its editing and creation are performed automatically. More about Autogen here. Autogen serves for automatic generation of variables from data points and can be applied to an entire device containing multiple data points, groups etc.

Solution building

Solution build compiles all executable projects, HMI interfaces, function libraries and HMI libraries into a single binary file used by the Mervis OS runtime. During the process, the system checks the validity of all configurations and will warn you if anything would prevent a successful compilation.

To start the compilation go to the upper ribbon and click on Build Solution.

A Selected Devices for Build window will appear - a list of connected PLCs the project can be compiled for. By default, the system selects all available controllers, terminals or web interfaces. Confirm your selection by clicking on OK.

This step will start the compilation itself. The Results tab on the bottom panel will display any messages displayed during the compilation. The compilation progress can be monitored in the status bar. If you performed all the instructions above correctly, the compilation should be completed successfully and the status bar should display “Solution build succeeded”.

Deploying the solution

Deploying the solution marks the process of uploading the compiled binary file into the controller and starting it in Full Run Mode. To deploy the solution click on Deploy Solution on the upper ribbon.

As with the solution build, Deploy Solution will also display a list of controllers to deploy the solution to. Confirm your selection by clicking on OK.

The last step of uploading the solution is to set a new state for the controller. There are multiple options; for this tutorial, keep only Warm restart, Full Run and Memory Area 1+2. Confirm by clicking on OK.

With the project good to go, we will now move to create your first control program. Its purpose will be to periodically switch the Relay1 output. To switch the output will require setting Relay1 to alternate between True and False states. The basic executable project was generated automatically in Simple Mode, thanks to which we now have the main program available for creating the logic. In the left panel double-click on main.Program.fbd.

A program window will appear in the main window.

The FUPLA programming space is divided into three sections - the left side is reserved for Inputs with each grey box available for placing a single input variable.

The middle section is called logic section and will be used for the programming itself.

And finally, the right section is for placing outputs. As with the outputs, there is a number of grey boxes for placing output variables.

For demonstration and testing purposes you can create a simple logic for switching the above-mentioned Relay1. The entire logic will consist of predefined function blocks (FB) available in Mervis libraries. Each FB is designed for one specific function and contains an internal logic, its inputs to provide input data and outputs that can be connected to other FBs or hardware outputs.

Click on FUPLA Box Explorer - you can find it among tabs at the left panel's bottom edge.

The left panel's upper edge includes a search column for quick and easy search for blocks predefined by Mervis.

Let's find a pulse generator. Enter pulse generator into the search column. As the system searches through function blocks in real-time, the number of results will gradually decrease. After entering the entire name of the block, only a single result will remain - the Pulse Generator (BD2) block. Click on it, hold the mouse button and drag the block over to the logic section. Then place the block by releasing the button.

The BD2 Pulse Generator contains a simple logic - by default the block periodically alternates the Out output between True and False at 1 Hz frequency. Let's take a closer look at its inputs. Enable input and outputs Out and OutN are visible on the FB itself. However, if you double-click the block it will change its colour to yellow - an indication of selection. The Properties panel will then display a complete list of inputs and outputs. As you can see there are many more inputs than those visible in the main window, as most of the inputs/outputs are hidden by default. Visibility of the individual inputs/outputs can be toggled by the Visible property. As we need only the pulse generator's Out output, un-check the Visible box for all inputs/outputs except Out. Bear in mind Mervis IDE does not allow any unconnected inputs in the logic section and any attempt to build such a solution will fail. The last step is to set 5s interval for Ttrue and Tfalse - that will ensure the relay will switch open/close every 5 seconds.

Note:: you can display additional info about any block by selecting it and pressing F1 to open the help page for the block.

You now need to connect the pulse generator's output to Relay1 input. Right-click on input section to display a context menu, move the cursor over Global Variables and from the submenu choose Insert existing variable.

In the Insert existing variables, a list of all available variables, inputs and outputs of your controller will be displayed. If the list is nearly empty, you probably did not use Autogen to define variables available for your PLC. In that case, right-click on devices in both I2C and Modbus TCP channels and click on Set autogen in the context menu.

If you followed the guide closely, Simple Mode already generated all variables for the program.

Autogen generates variables based on all available or selected data points of inputs and outputs. That means we need to generate this list to use the PLC's inputs/outputs in the program. Bear in mind it is a one-off generation. If you, for example, rename any of the inputs/outputs of your device, you will need to set Autogen again.

Alternatively, you can double-click on Unipi1_Relays / Unipi1Lite_Relays and set the Autogen manually by right-clicking on the Relay1 data point and selecting Set Autogen in the context menu. You can use this method for other devices as well.

In the Insert existing variable dialogue window a long list of available variables will appear. You can search for variables manually, or you can try to find it by its name. For this tutorial, we will enter Relay, as all relays on Unipi 1.1/1.1 Lite are named as such. On Unipi 1.1 you have 8 changeover relays available, with Unipi 1.1 Lite having only 6 of them. A relay is always named RelayN with N representing a specific relay number (1-8). Click on Relay1 and confirm by clicking on OK.

The output variable will appear in the output section in the location we right-clicked on previously. We now need to connect the Relay1 output variable and the pulse generator's output. Move your cursor over the small black dot next to the Out name on the pulse generator. A small box will appear containing info about the output's type.

Click on the dot, hold the mouse button and move the cursor to a similar black dot placed next to the Relay1's name. A green line will appear between both outputs. After releasing the mouse button, the line will change to orange.

You can now try to build the solution - see Building and uploading the solution. If you did everything right, a Build succeeded message will appear in the status bar. Warning messages displayed in the Results tab can be safely ignored.

If the build succeeded and you followed the instructions above correctly, you can upload the solution into the controller - see Building and uploading the solution.

Upon uploading the solution the Relay1 relay output will be switched every 5 seconds.



Congratulations, your first Unipi 1.1 project is now complete!