Table of Contents
MPINO STUDIO2 · Connecting an HMI with Modbus RTU
← STUDIO2 installation and start · Next: Building the HMI Screen → · Optional: LS Electric Cnet →
When you set the protocol to Modbus RTU Slave in MPINO STUDIO2, the app generates the product's request-handling code. The HMI sends requests as the Modbus RTU Master. The internal D words the HMI reads and writes map to Holding Registers, and M bits map to Coils. The addresses in STUDIO2's generated code are different from those in the Arduino IDE SDK examples.
The table shows 0-based addresses inside the Modbus request that STUDIO2's generated code accepts. If your HMI takes 1-based Coil numbers, M0 may appear as 1001. For the numbers to enter in 1-based or 4xxxx notation, check the HMI driver manual and follow the HMI address format.
| HMI element | STUDIO2 memory | Modbus area | 0-based address in the request |
|---|---|---|---|
| Number that changes every second | D0 | Holding Register | 2000 |
| Number input | D1 | Holding Register | 2001 |
| Number that returns the input value | D2 | Holding Register | 2002 |
| Switch and check lamp | M0 | Coil | 1000 |
| Lamp for the ladder result | M1 | Coil | 1001 |
This simple example uses only internal memory on MPINO-8A4R-S · RS-232 Serial1 · station 1 · 9600 bps · 8N1. It does not use real I/O terminals. For channels, wiring, installation, and product selection, see Wiring the HMI and STUDIO2 installation and start.
1. New project and internal memory
- Select
MPINO-8A4R(T)-Sunder File → New and save the project asHMI_First_Test.mp2. - Under Settings → Memory Area Settings, set P to
64and M, D, C, T, and R to16each. These numbers are counts, not addresses. - Under Settings → Ladder Pin Map Settings, clear Use for all physical input and output pins. This program uses only internal
MandD.
The communication terminals differ by product. Check your product's port in the channel table.
2. One ladder rung and the main code
In the Explorer, open Ladder → ladderLoop. Place an NO contact (F2) M0 at row 1, column 1, and an output coil (F9) M1 at row 1, column 2. M1 is an internal bit, not a real relay output.
Open the main code tab under Code and enter the code below. This code goes in main of the STUDIO2 project. It is not a stand-alone sketch for Arduino IDE.
#include "mpino_runtime.h" #include "ladder_generated.h" unsigned long lastTick = 0; void setup() { M[0] = false; M[1] = false; D[0] = 0; D[1] = 0; D[2] = 0; lastTick = millis(); } void loop() { ladderLoop(); unsigned long now = millis(); if (now - lastTick >= 1000UL) { lastTick = now; D[0] = (D[0] + 1) % 100; } D[2] = D[1]; }
D0 repeats 0~99 once per second. When the HMI writes a number to D1, D2 follows it. When M0 turns on, the ladder turns on M1. STUDIO2 generates the communication initialization and request handling from the communication settings, so do not add ImodbusRTUInit() or ImodbusRTU() to this code.
3. Run → Communication
Enter the values in the table below. The figure shows an initial screen to locate each item. Its protocol None and baud rate 115200 are not the values for this exercise. Change them to Modbus RTU Slave and 9600, then save.
| Figure no. | Item | Value |
|---|---|---|
| ① | Channel | Serial1 — the RS-232 port on this product |
| ② | Protocol | Modbus RTU Slave |
| ③ | Slave ID | 1 |
| ④ | Baud Rate | 9600 |
| ⑤·⑥·⑦ | Data Bits · Stop Bits · Parity | 8 · 1 · None |
Enter these values under Run → Communication and press Ctrl+S to save. On the HMI side, set the RS-232 port you connected to Modbus RTU Master with the same station number and communication settings.
4. Build, upload, and HMI addresses
- Run Run → Build (
Ctrl+R) and check for the success message in Build Output. - In the status bar, select the PC COM port of the MP Download Cable for your product, then run Run → Upload (
Ctrl+U). Confirm that the upload log in the bottom panel ends normally. The upload port andSerial1for the HMI are separate connections. For screens and steps, see Select a Port and Upload. - Connect the three HMI numbers and the bit switch and lamp according to the address table above. Set numbers to signed 16-bit integer, 1 word, 0 decimal places, scale 1, and set the input range to
0~9999.
Actual HMI communication in this example must be checked separately for your HMI model and cable. Do not assign the same Serial1 to ladder monitoring or user serial code as well.
First assign this page's Modbus addresses in Building the HMI Screen, then continue with Checking Operation and Troubleshooting. To try Cnet as well, switch the same program to LS Electric Cnet →.
