Both serial link(Modbus RTU) and/or Ethernet (Modbus TCP) can be used as communication interface (based on the configuration of the microcontroller itself).
For this communication in the PROMOTIC system can be used: PmModbusMr - Driver for communication by the Modbus Master protocol.
Such protocol can be programmed into Arduino (will be Slave) and also into PROMOTIC application (will be Master).
For this communication in the PROMOTIC system can be used: PmChar - Driver for communication by user defined ASCII/BIN protocol.
The Arduino can be functionally extended. In order to do that it contains inputs and outputs called "pins". These pins can be used to connect additional circuits, chips, relays, memories etc. There are simple functions available in the Arduino to be used with these pins.
Programming the analog input and output values is more complex than the digital values. The description "Analog" is not precise in this case because these are in fact not analog values. If it is necessary to use real analog value in the range for example 0-5V, then using an external D/A converter would be necessary. This is caused by the fact that PWM signal is being generated on selected pins - this is considered to be a kind of analog signal "imitation". In reality the values between 0 and 5V are alternated very quickly.
#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>
modbusDevice regBank; //Setup the brewtrollers register bank. All of the data accumulated will be stored here
modbusSlave slave; //Create the modbus slave protocol handler
void setup()
{
pinMode(2, INPUT); //Declare DI2
pinMode(13, OUTPUT); //Declare LED as output
regBank.setId(1); //Assign the modbus device ID
regBank.add(10002); //Add Digital Input register
regBank.add(13); //Add Digital Output register
regBank.add(30001); //Add Analog Input register
slave._device = ®Bank; //Assign the modbus device object to the protocol handler
slave.setBaud(9600); //Initialize the serial port for coms at 9600 baud
}
void loop()
{
byte DI2 = digitalRead(2); //Digital Input
if(DI2 >= 1)regBank.set(10002,1);
if(DI2 <= 0)regBank.set(10002,0);
int DO13 = regBank.get(13); //Digital output
if(DO13 <= 0 && digitalRead(13) == HIGH) digitalWrite(13,LOW);
if(DO13 >= 1 && digitalRead(13) == LOW) digitalWrite(13,HIGH);
float valueAI0 = analogRead(0); //Analog Input
regBank.set(30001, (word)valueAI0);
slave.run();
}
float val;
char received;
void setup()
{
pinMode(2,INPUT); //Declare DI2
Serial.begin(9600); //Begin serial communication
}
void loop()
{
while(Serial.available() > 0)
{
received = Serial.read();
if(received == 'a')
{
val = analogRead(0);
val = val*(5.0/1024.0);
Serial.println(val);
}
else if(received == 'd')
{
val = digitalRead(2);
Serial.println(val);
}
}
}