Connecting Arduino MEGA 2560 to Weintek HMI operator panel

There is a project in which an Arduino UNO is connected to a Weintek operator panel via the Modbus protocol using an RS485 module: GitHub - AReds4/Arduino2HMI: This project contains all the required materials in order to initiate a Modbus connection guide between a Human Machine Interface and an Arduino. As well as examples of how to address bit/integer data.
The project uses the library: https://github.com/jossef/arduino-modbus-slave/tree/master/%20arduino-modbus-slave
Everything works great on Arduino UNO, but if you load the same project on MEGA 2560, nothing works. The TXD and RXD pins of the RS485 module are connected to pins 0(RX) and 1(TX) of the UNO board.
On MEGA, if you connect the TXD and RXD contacts to pins 0 and 1, then the RS485 module does not show any signs of life; if you connect it to pins 14 and 15, 16 and 17, 18 and 19, 20 and 21, then the RS485 module starts blinking. How to connect Arduino MEGA 2560 to Weintek panel? Maybe something needs to be changed in the library? I dug around in the library, but still couldn't figure it out.
Project code:

#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>

modbusDevice regBank;
modbusSlave slave;

#define RedPin 12
#define YellowPin 11
#define GreenPin 10

void setup()
{   
  regBank.setId(0); ///Set Slave ID

  regBank.add(1);//Red
  regBank.add(2);//Yellow
  regBank.add(3);//Green

  pinMode(RedPin,OUTPUT);//Red Light
  pinMode(YellowPin,OUTPUT);//Yellow Light
  pinMode(GreenPin,OUTPUT);//Green light
 
 slave._device = &regBank; 
  slave.setBaud(9600);
}
void loop(){

  //Control LED Lights's 
    int RedLED = regBank.get(1);
      if (RedLED <= 0 && digitalRead(RedPin) == HIGH)digitalWrite(RedPin,LOW);
      if (RedLED >= 1 && digitalRead(RedPin) == LOW)digitalWrite(RedPin,HIGH);
      
    int YellowLED = regBank.get(2);//Controls the 
      if (YellowLED <= 0 && digitalRead(YellowPin) == HIGH)digitalWrite(YellowPin,LOW);
      if (YellowLED >= 1 && digitalRead(YellowPin) == LOW)digitalWrite(YellowPin,HIGH);
      
    int GreenLED = regBank.get(3);//Controls the Green
      if (GreenLED <= 0 && digitalRead(GreenPin) == HIGH)digitalWrite(GreenPin,LOW);
      if (GreenLED >= 1 && digitalRead(GreenPin) == LOW)digitalWrite(GreenPin,HIGH);

slave.run(); 
}


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.