macroland
Hello,
 
i want to use one Mega2560 as inputs only which should be 66pins.
 
I have changed the pins accordingly
[203128%2F9404133%2Fmceclip0]
 
The Communication is set to RTU:
[203128%2F9404134%2Fmceclip0]
 
I compiled the blank_Project to the MEGA.
 
on the Pi runtime i set up the slave device :

As i changed the standard Pin Mapping for the MEGA i uses generic Modbus RTU Device:
[203128%2F9404136%2Fmceclip0]
 
I have second Mega Connected on USB0 with the standard MEGA Pin Mapping but both devices fail to connect
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Device MegaXB1 is disconnected. Attempting to reconnect...
Persistent Storage is empty
Connected to MB device MegaXB1
Modbus Read Discrete Input Registers failed on MB device MegaXB1: Connection timed out
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued stop_dnp3() command
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
Issued start_snap7() command
Snap7: 2025-07-21 09:22:49 Server started
Modbus Write Coils failed on MB device MegaXB1: Connection timed out
Modbus Read Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Holding Registers failed on MB device MegaXB1: Connection timed out
Device MEGA_XA is disconnected. Attempting to reconnect...
Connected to MB device MEGA_XA
Server: Client accepted! Creating thread for the new client ID: 11...
Server: waiting for new client...
Server: Thread created for client ID: 11
Modbus Read Discrete Input Registers failed on MB device MEGA_XA: Connection timed out
Modbus Read Discrete Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Coils failed on MB device MegaXB1: Connection timed out
Modbus Read Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Holding Registers failed on MB device MegaXB1: Connection timed out
Modbus Read Discrete Input Registers failed on MB device MEGA_XA: Connection timed out
Modbus Read Discrete Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Coils failed on MB device MegaXB1: Connection timed out
Modbus Read Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Holding Registers failed on MB device MegaXB1: Connection timed out
Modbus Read Discrete Input Registers failed on MB device MEGA_XA: Connection timed out
Modbus Read Discrete Input Registers failed on MB device MegaXB1: Connection timed out
Modbus Write Coils failed on MB device MegaXB1: Connection timed out
 
Did i miss something to set up this custom device?
What i dont understand is my the other MEGA with standard mapping is failing to which had worked before
Reply 0 0
macroland
Sometimes it is easer then expected
 
  1. the Serial Ports where mixed up.
  2. an the size would need to be 64
Reply 0 0
thiagoralves
And start address must be zero
Reply 0 0
macroland
And start address must be zero
Yes that as well but now i have a different problem. the original output pins are not recieved as Inputs. do i need to change something else ? Maybe the physical definition of the output pins?
Reply 0 0
thiagoralves
From the pictures you sent, you've used some pins as analog inputs and others as digital inputs. You need to map them accordingly on your slave device modbus configuration. Digital inputs are mapped to input status and analog inputs are mapped to input registers. Additionally, the modbus buffer on the Arduino Mega is quite limited in size due to the size of its RAM (8KB total). It is possible that all pins might not fit in the modbus buffer.
Reply 0 0
macroland
so if i understand correctly i would need to create a .ino file which basicly makes the mega a modbus RTU slave
Reply 0 0
thiagoralves
Maybe that would be the best and easiest approach
Reply 0 0
macroland
I have tried to make a custom RTU device however i keep getting Timeout errors which is probaly on the Mega Side.

I have also ried to edit the HAL-Files and the Board JSON which kinda worked but for some reason i still cant get any inputs from my old Outputs although defined in the code. Does the Compiler change something to force the outputs to be outputs again?
Reply 0 0
thiagoralves
No, if you’ve defined pins to be inputs, they are inputs. You can test this by loading a project that reads these input pins and then debugging the project on the editor connected to the Arduino Mega. I believe the problem is indeed the Modbus buffer size that can’t accommodate as many pins in the input status. That’s a limitation of the Modbus implementation on OpenPLC specifically for the Arduino Mega due to its small RAM footprint.
 
Implementing your own Modbus RTU through Arduino IDE should work. Just make sure you have the correct settings (baud rate, slave id, parity, etc). Test it using a Modbus software like Radzio first to ensure everything works
Reply 1 0
Reply