Hello!. Let me tell you.Run in Arduino Mega. The SCADA system uses the Modbus RTU protocol for data transmission and has two thermocouples and two pH meters. The system with two thermocouples and a pH meter goes perfectly and there are no problems of interference or failures of any kind on the server. The thing is that by connecting the second pH meter as it collapses and the server goes, I think that because it has problems processing the data of the RX3 TX3 and the RX2 TX2 at the same time we say. Obviously that has to be a matter of doing proper programming. And that’s where I fail … it occurs to you how to make sure they do not overlap. I leave the code: * The value of the pH meter is “sensorstring” and “sensorstring1”. Many thanks friends
#include <Adafruit_MAX31856.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
Adafruit_MAX31856 max_B = Adafruit_MAX31856(9, 11, 12, 13);
String termoparstring_A = "";
String termoparstring_B = "";
String inputstring = "";
String sensorstring = "";
String inputstring1 = "";
String sensorstring1 = "";
boolean input_string_complete = false;
boolean sensor_string_complete = false;
boolean input_string_complete1 = false;
boolean sensor_string_complete1 = false;
void configure_mb_slave(long baud, char parity, char txenpin);
int update_mb_slave(unsigned char slave, int *regs, unsigned int regs_size);
enum {
COMM_BPS = 9600,
MB_SLAVE = 1,
PARITY = 'n'
};
enum {
T_1,
T_2,
pH_1,
pH_2,
MB_REGS
};
int regs[MB_REGS];
unsigned long wdog = 0;
unsigned long tprev = 0;
void setup() {
configure_mb_slave(COMM_BPS, PARITY, 0);
Serial3.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
inputstring.reserve(30);
sensorstring.reserve(60);
inputstring1.reserve(30);
sensorstring1.reserve(60);
max_A.begin();
max_A.setThermocoupleType(MAX31856_TCTYPE_K);
max_B.begin();
max_B.setThermocoupleType(MAX31856_TCTYPE_K);
}
void serialEvent() {
inputstring = Serial1.readStringUntil(13);
input_string_complete = true;
}
void serialEvent3() {
sensorstring = Serial3.readStringUntil(13);
sensor_string_complete = true;
sensorstring1 = Serial2.readStringUntil(13);
sensor_string_complete1 = true;
}
void loop() {
update_mb_slave(MB_SLAVE, regs, MB_REGS);
termoparstring_A =(max_A.readThermocoupleTemperature());
termoparstring_B =(max_B.readThermocoupleTemperature());
regs [T_1] = (max_A.readThermocoupleTemperature()*100); // ec. del sensor y *100.0 para que aparezcan decimales en el SCADA
regs [T_2] = (max_B.readThermocoupleTemperature()*100); // ec. del sensor y *100.0 para que aparezcan decimales en el SCADA
regs [pH_1] = (sensorstring.toFloat()*100);
regs [pH_2] = (sensorstring1.toFloat()*100);
sensorstring = "";
sensorstring1 = "";
sensor_string_complete = false;
sensor_string_complete1 = false;
}