|
| 1 | +--- |
| 2 | +title: 'ModBus Setup with Arduino PLC IDE' |
| 3 | +description: 'This tutorial will show you how to set up the ModBus communication with the Arduino PLC IDE.' |
| 4 | +tags: |
| 5 | + - PLC |
| 6 | + - ModBus |
| 7 | +author: 'Pablo Marquínez' |
| 8 | +hardware: |
| 9 | + - hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control |
| 10 | +software: |
| 11 | + - plc-ide |
| 12 | +--- |
| 13 | + |
| 14 | +## Overview |
| 15 | + |
| 16 | +The Arduino Portenta Machine Control (PMC) is a fully-centralized, low-power, industrial control unit. For equipment and machinery control, industrial communication protocols, such as Modbus RTU over RS485 and Modbus TCP/IP over Ethernet, can be implemented in the PMC. In this tutorial, we will learn about how to get started on how to configure the ModBus communication with the Arduino PLC IDE. |
| 17 | + |
| 18 | +## Goals |
| 19 | + |
| 20 | +- Configure the ModBus communication (RTU and TCP) |
| 21 | + |
| 22 | +## Required Hardware and Software |
| 23 | + |
| 24 | +- [Arduino Portenta Machine Control](https://store.arduino.cc/products/arduino-portenta-machine-control) board |
| 25 | +- [Arduino PLC IDE](../../../../software/plc-ide) license |
| 26 | + |
| 27 | +## Set Up |
| 28 | + |
| 29 | +In order to configure the Portenta Machine Control you will need to connect to the device through the Arduino PLC IDE. |
| 30 | + |
| 31 | +1. Connect the device to the computer through USB |
| 32 | +2. Click "Connects to the target" button on the PLC IDE |
| 33 | + |
| 34 | +***The device needs to be activated with a license, check the steps on the [PLC IDE Set-up tutorial](./plc-ide-setup-license)*** |
| 35 | + |
| 36 | +***Both ModBus RTU and ModBus TCP can run at the same time in parallel*** |
| 37 | + |
| 38 | +## Configure The ModBus RTU Communication |
| 39 | + |
| 40 | +***Important: Once you use the ModBus Mode to Master/Slave the RS485 ports will be only dedicated to ModBus, so the RS485 protocol is not accessible while using ModBus*** |
| 41 | + |
| 42 | +### ModBus RTU Configuration |
| 43 | + |
| 44 | +Inside the Arduino PLC IDE navigate to the left side panel and click on the "Resources" tab. |
| 45 | + |
| 46 | +To configure the ModBus communication click on the "RS485 Serialport" label, it will open a new window on the middle to customize: |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +Then you can attach some functions to the Generic Modbus item, they will appear also in the **Catalog Tile Window**, you need to select first the **Generic Modbus_01** |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +#### Mode |
| 57 | + |
| 58 | +* Not used |
| 59 | +* ModBus RTU Master |
| 60 | +* ModBus RTU Slave |
| 61 | + |
| 62 | +#### Baud Rate |
| 63 | + |
| 64 | +Bauds per second of the clock, options: |
| 65 | + * 600 |
| 66 | + * 1200 |
| 67 | + * 2400 |
| 68 | + * 4800 |
| 69 | + * 9600 |
| 70 | + * 19200 |
| 71 | + * 38400 |
| 72 | + * 57600 |
| 73 | + * 115200 |
| 74 | + |
| 75 | +#### Serial Mode |
| 76 | + |
| 77 | +| Name | Parity | data bits | stop bits | |
| 78 | +| ------- | ----------- | --------- | ----------| |
| 79 | +| N, 8, 1 | No parity | 8 | 1 | |
| 80 | +| E, 8, 1 | Even parity | 8 | 1 | |
| 81 | +| O, 8, 1 | Odd parity | 8 | 2 | |
| 82 | +| N, 8, 2 | No parity | 8 | 2 | |
| 83 | +| O, 8, 2 | Odd parity | 8 | 2 | |
| 84 | + |
| 85 | +#### Slave Settings |
| 86 | + |
| 87 | +(Only available on slave mode) |
| 88 | + |
| 89 | +* ModBus address |
| 90 | + Address of the device, from 1 to 247, it can not be repeated within the same ModBus net. |
| 91 | + |
| 92 | +#### ModBus Node Configuration |
| 93 | + |
| 94 | +Once you have configured your device as a **ModBus Master** you can attach some blocks to configure it, you can see them while you have the **RS485 SerialPort** on the **Catalog Tile Window** |
| 95 | + |
| 96 | + |
| 97 | +* Generic Modbus |
| 98 | + Configure the device name, Modbus address and the minimum polling time. |
| 99 | + |
| 100 | +### ModBus TCP Configuration |
| 101 | + |
| 102 | +***Important: Once you use the ModBus Mode, the ethernet port will be only dedicated to ModBus, so the ethernet protocol is not accessible while using ModBus*** |
| 103 | + |
| 104 | +Inside the Arduino PLC IDE navigate to the left side panel and click on the "Resources" tab. |
| 105 | + |
| 106 | +To configure the ModBus communication click on the "Ethernet" label, it will open a new window on the middle to customize: |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +* ModBus TCP Master: Enables the Master mode on the TCP bus (ModBus) |
| 111 | +* ModBus TCP Slave: Always enabled, address 255 |
| 112 | + |
| 113 | +Then you can attach some functions to the Generic Modbus item, they will appear also in the **Catalog Tile Window**, you need to select first the **Generic Modbus device** |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +Settings: |
| 122 | +* Name |
| 123 | +* IP address |
| 124 | +* Minimum polling time |
| 125 | + |
| 126 | +## ModBus Parametrization |
| 127 | + |
| 128 | +On the Generic |
| 129 | + |
| 130 | + |
| 131 | +## ModBus Devices Functions (Modbus FC) |
| 132 | + |
| 133 | +* Modbus FC-01: This will read the status of the coils (digital outputs) |
| 134 | +* Modbus FC-02: Reads the discrete inputs |
| 135 | +* Modbus FC-03: Reads the holding registers |
| 136 | +* Modbus FC-04: Read the input registers |
| 137 | +* Modbus FC-05: Writes single coil state |
| 138 | +* Modbus FC-06: Write single register |
| 139 | +* Modbus FC-15: Write multiple coils |
| 140 | +* Modbus FC-16: Write multiple registers |
| 141 | + |
| 142 | +To configure the block you can click on it and it will show the configuration panel on the main window. |
| 143 | + |
| 144 | + |
| 145 | +Inside each of the "devices" (functions) you can set its: |
| 146 | +**General** |
| 147 | +* Start address |
| 148 | +* Polling time |
| 149 | +* Time Out |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +**Coil/Register/Table** |
| 154 | +This is a table to link all the coils, registers or variables that the function is going to poll/write. |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +### Next Steps |
| 159 | + |
| 160 | +- Configure it as a ModBus Master device and connect a ModBus sensor to get data from. |
| 161 | +- Interconnect two Portenta Machine Control boards and create a sketch to communicate between them. |
0 commit comments