ScadaBR with Arduino via Modbus TCP/IP

Demonstrating the procedures necessary for Arduino to communicate with ScadaBR using another category of the modbus protocol: the modbus TCP/IP.
components
Hardware Components
Software Apps and online services
Scadabr
details

scadabr.PNG

we will demonstrate the procedures necessary for Arduino to communicate   with  ScadaBR using another category of the modbus protocol: the modbus TCP/IP.


Get to work – Establishing communication between an Arduino board and the ScadaBR

Required components

 

assembling the project

Hardware used.
Figure 1 – Hardware used.

programming

 

#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>
const int LED_COIL = 0;
ModbusIP mb;
void setup ()
{
mac byte [] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED }
byte ip [] = { 192, 168, 25, 16 } ;
mb. config ( mac,ip ) ;
pinMode ( 9, OUTPUT ) ;
mb. addCoil ( LED_COIL ) ;
}
void loop ()
{
mb. task () ;
digitalWrite ( 9, mb. Coil ( LED_COIL )) ;
}

Configuring Scadabr

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

Accessing the Data sources creation panel in SCADABR
Figure 2 – Accessing the Data sources creation panel.

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.

Creating Data Source of Modbus IP type.
Figure 3 – Creating the Modbus IP Data Source.

 

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).

 

Figure 4 - Defining Initial Data Source Settings.
Figure 4 – Configuring Initial Data Source Settings.

 

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 .

Figure 5 - Configuring the communication port and Arduino IP.
Figure 5 – Configuring the Arduino communication port and IP.

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 .

 

Figure 6 – Data points table.

 

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.

Figure 7 – Creating a new Data point.

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.

 

Figure 8 – Data point created.

 

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.

 

Figure 9 – Saving Data source settings.

 

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.

Figure 10 – List of Data points created.

After performing the procedure mentioned above, our Data point will appear created on the right side of the interface presented in our watchlist.

Figure 11 – Data point initial value.

.

 

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).

Figure 12 – Manipulating the Data point.

See the result of the activation of the led in ScadaBR.

Figure 13 – Data point final value .

 


understanding in depth

software

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.

#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>

– 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).

const int LED_COIL = 0;

– 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.

ModbusIP mb;

– 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.

void setup () {
mac byte [] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED }
byte ip [] = { 192, 168, 25, 16 } ;
mb. config ( mac,ip ) ;
pinMode ( 9, OUTPUT ) ;
mb. addCoil ( LED_COIL ) ;
}

– 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  .

void loop () {
mb. task () ;
digitalWrite ( 9, mb. Coil ( LED_COIL )) ;
}

 


Final considerations

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.

COMMENTS

Please Login to comment
  Subscribe  
Notify of