we will demonstrate the procedures necessary for Arduino to communicate with ScadaBR using another category of the modbus protocol: the modbus TCP/IP.
Original post: https://portal.vidadesilicio.com.br/scadabr-modbus-tcp-ip/
Get to work – Establishing communication between an Arduino board and the ScadaBR
- 1 x Arduino UNO
- 1 x Shield Ethernet Wiznet W5100
- 1 x Protoboard
- 1 x Resistor 330 Ω
- 1 x Diffuse green LED
assembling the project
At this moment, we are going to present the initial procedures that must be done in ScadaBR so that it is possible to carry out the interaction between it and our Arduino board . First, to fulfill the presented objective, we must make ScadaBR identify the element with which it will communicate. This must be done by creating an element called Data source, which in turn will be the bridge between the Arduino board we are using and ScadaBR.
Data source is the structure that allows communication between Arduino and ScadaBR
Then, when creating the Data point, we must say what type of communication will exist between the 2 elements. As mentioned before, we will use the Modbus protocol through serial communication, so just find the Modbus IP option in the selection list and click on the icon to the right of the list in question.
Then, ScadaBR will direct us to a page, in which we must define the parameters of the Data source in question (remember that it is the bridge between Arduino UNO and ScadaBR ). At first, we should just name our Data source and also define the time when the data will be updated (this information is very important, that is, it is essential that the reader is aware of the application that is being developed so that the choosing this parameter results in an efficient functioning of the project).
In addition to these settings, we must also specify a few parameters for the communication to be established established, such as: the endeceço IP previously configured on the code UNO Arduino and the type of transport (we suggest the “TCP to stay alive” in a There is no need to change the Port field .
After creating and configuring the Data source , we must create a small structure called Data point . Data points are the elements that will contain the values related to the inputs and outputs of our Arduino board . To perform this procedure, go to the bottom of the screen and then click on the icon located to the right of the table referring to Data points .
After clicking on the aforementioned icon, ScadaBR will give us a window with some options to be defined. First, we must name the Data point (in this tutorial, we call it LED). Next, we must ensure that the Record Range field has the Coil Status option selected. To save the settings made, just click on the icon at the top right of the window.
As this is an introductory tutorial, we won’t cover how the other fields work.
The following figure shows how the table where the Data points are organized will look like after the previous creation. To enable the desired data point, just click on the red circle present in the Status field of the created data point.
Finally, we must go to the top of the page, save the settings made (the same procedure as performed in the previous step) and enable the Data source, clicking again on the red circle beside the icon used to save.
At this moment, the reader must return to the watch list (first icon from the left in the toolbar) and on the left side of the presented interface, click on the arrow to visualize the status of the created data point.
After performing the procedure mentioned above, our Data point will appear created on the right side of the interface presented in our watchlist.
To activate the led, just position the mouse over the icon located to the left of the Data point’s name and change its value (note that when its value is 0 (zero), the led will be off, while when we change it for 1 (one) the led will be turned on).
See the result of the activation of the led in ScadaBR.
understanding in depth
At this point, all the steps for the development of the code that must be inserted in Arduino UNO so that it is possible to carry out the communication between it and ScadaBR will be demonstrated .
– Including the libraries that will be used
The first step in establishing communication between the two elements consists in the inclusion of appropriate libraries for the use of the Modbus TCP/IP protocol (developed by André Sarmento and available here ). In addition, we must also declare the libraries responsible for the functioning of the SPI communication protocol and for the connectivity of our Arduino board with the local network.
– Defining Modbus protocol structures
Later, we must determine the structure that will be responsible for activating the LED. In this tutorial, we will address only one among the other structures that exist in the MODBUS protocol: the Coils . These elements act in the storage of values that can be used to trigger on/off devices.
To define the Coil that will be used to activate the LED, just declare a variable of type const int and then assign a number to it according to the amount of Coils in use in the project (as in this application we are using only one Coil, we assign the number 0 (zero) to the declared variable).
– Creating the mb object
Before proceeding to the setup() function , an object called mb must be created so that we can control the existing structures in the Modbus protocol.
– Defining initial settings
In the Setup() function there are some lines of code referring to the initial settings of the program. First, we must define some parameters related to the communication protocol used, so that this procedure is performed by defining the MAC and IP addresses of our Arduino UNO board (in practice, the MAC address can be anything, as long as it is unique on the network, while the IP address must be a valid address on your local network). Then, to configure our Modbus protocol, we use the config() function together with the values determined above.
Then, we use the pinMode() function to define the operating mode of digital pin 9 as a digital output and finally, we add the Coil that will be responsible for containing the values used in the activation of the LED.
– Carrying out the LED activation
Within the loop() function , we use the task() function to manage communication and data exchange between devices that are connected via Modbus protocol . In addition to the aforementioned function, we also have the necessary function to write the data referring to the activation of the LED in the Coil instance .
In this tutorial, we demonstrate how you can establish communication between your Arduino board and ScadaBR through a local network, we hope you will keep following us and feel free to give us suggestions, criticisms or compliments.