i have tried to use the start guide for OPTA and RS 485, but that tutorial isn't helping with the project.
I have a device sending half duplex RS485 SLAVE ID 7, 8N1, 9600.
i am able to read 100 holding and input registers on an UNO rev 3 with MK485 without issue.
so i got an OPTA RS485. i downloaded PLC IDE and had to revert that version to get the license to work.
on the OPTA with the below code i keep getting 226 time out errors just working the the RS485 portion. havent began to tackle the modbus tcp.
the instructions for the PLC IDE are better on the finder website.
any insight would be great
#include <ArduinoRS485.h> // RS485 library for handling half-duplex communication
#include <ModbusMaster.h> // Modbus RTU Master library
// Modbus parameters
const uint8_t SLAVE_ID = 7; // Slave device ID
const uint16_t HOLDING_REG_START = 0; // Start address of holding registers
const uint16_t HOLDING_REG_COUNT = 156; // Number of holding registers to read
const uint16_t INPUT_REG_START = 0; // Start address of input registers
const uint16_t INPUT_REG_COUNT = 121; // Number of input registers to read
// Modbus RTU instance
ModbusMaster modbusRTU;
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize RS485 communication on Serial2
RS485.begin(9600); // Baud rate 9600, 8N1 by default
// Configure Modbus RTU with the RS485 bus
modbusRTU.begin(SLAVE_ID, RS485);
Serial.println("Modbus RTU Master started.");
}
void loop() {
// ====== Read Holding Registers ======
uint8_t result = modbusRTU.readHoldingRegisters(HOLDING_REG_START, HOLDING_REG_COUNT);
if (result == modbusRTU.ku8MBSuccess) {
Serial.println("Holding Registers (16-bit short):");
for (uint16_t i = 0; i < HOLDING_REG_COUNT; i++) {
short value = (short)modbusRTU.getResponseBuffer(i); // Read as 16-bit short
Serial.print("Reg[");
Serial.print(i);
Serial.print("]: ");
Serial.println(value);
}
} else {
Serial.print("Error reading holding registers: ");
Serial.println(result);
}
// ====== Read Input Registers ======
result = modbusRTU.readInputRegisters(INPUT_REG_START, INPUT_REG_COUNT);
if (result == modbusRTU.ku8MBSuccess) {
Serial.println("Input Registers (16-bit short):");
for (uint16_t i = 0; i < INPUT_REG_COUNT; i++) {
short value = (short)modbusRTU.getResponseBuffer(i); // Read as 16-bit short
Serial.print("Reg[");
Serial.print(i);
Serial.print("]: ");
Serial.println(value);
}
} else {
Serial.print("Error reading input registers: ");
Serial.println(result);
}
delay(1000); // Wait before the next cycle
}