I got an Opta rs485. Unfortunately I am unable to get modbus rtu up and running. The rs485 bus inlcudes one master (my pc via usb adapter), one opta and one energy meter. I am able to read registers from the energy meter. Therefore the wiring should be ok.
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
#define MODBUS_RTU_SLAVE_ID 3
#define MODBUS_RTU_BAUDRATE 9600
void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Startup");
// start the Modbus RTU server
if (!ModbusRTUServer.begin(MODBUS_RTU_SLAVE_ID, MODBUS_RTU_BAUDRATE, SERIAL_8N1)) {
Serial.println("Failed to start Modbus RTU Server!");
while (1)
;
}
if (!ModbusRTUServer.configureHoldingRegisters(0x4000, 0x6050 - 0x4000)) {
Serial.println("Failed to configure RTU Holding registers!");
while (1)
;
}
ModbusRTUServer.holdingRegisterWrite(0x4000, 0x1234);
Serial.println("Setup done");
}
void loop() {
ModbusRTUServer.poll();
}
I just found the new tutorial https://docs.arduino.cc/tutorials/opta/getting-started-with-modbus-rtu and tried the server and client example. Additionally I reduced the rs485 network to Opta, pc adapter and IO Ninja Serial Tap. I use IO Ninja to sniff the bus. Running the server example does not show any response in the sniffed log. Running the client shows tons of line errors in the sniffing log. I fast guess is that the example is running on a wrong baud rate or false serial configuration. So the next step would be to capture a full frame using logic a logic analyzer or osziliscope.
I am also having a problem with the arduinoModbus library on the finder opta (ModbusRtuClient). I connected the RS485 output to a RS485 to usb adapter into my notebook running hercules terminal emulator and the packet I receive when the opta polls is missing the last byte. (ID,0x03,StartH,StartL,QtyH,QtyL,CRCL and that's it... ).
Usually the problem is that the software immediately shuts the RS485 transmit enable line when the last byte is buffered and not finished transmitting (you usually have to monitor the last byte status for transmit complete, or wait for 1 byte frame time at baudrate before closing the line). I am unfortunately a noob at arduino environment and can't for the life of me get into the guts of the code so I can fix the problem myself.
The debug flag is also hidden so deep in the library with no function to enable it.
Following up to the thread with our recent experience, over one year since this posting in 2023. The polarity markings A- / G / B+ on the OPTA 3-pin RS-485 block should be B+ / G / A- so as to not confuse other RS-485 devices made by other manufacturers.
An o-scope certainly shows this but for those looking to do a quick check, you can use a decent multimeter to measure DC volts across pins A and B.
Program the OPTA to make Holding request with a delay(5000) or so, and you can see a quick spike from zero to negative 50mv every 5 seconds. Once I switched the wires on A and B, the data came in as expected, no issues (after making sure baud, parity, stop bit were all set to the same across the Modbus network).