Hi everyone,
I'm hoping for some help diagnosing a persistent issue with my new Arduino Opta WiFi. I'm trying to communicate with a wind direction sensor via Modbus RTU, but I'm consistently getting a timeout error. I believe I have exhausted all standard troubleshooting steps and suspect a hardware failure.
Main Code (Opta as Modbus Client)
This is the primary code I am using on the Opta, which results in a timeout. It uses the official ArduinoModbus library and is configured according to the sensor's datasheet (9600 bps, 8N1, Slave ID 1, Register 0x0017).
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#define SLAVE_ID 1
#define BAUD_RATE 9600
#define SERIAL_CONFIG SERIAL_8N1
#define WIND_DIRECTION_REG 0x0017
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("--- Modbus RTU Client for Opta + Wind Sensor ---");
pinMode(LEDB, OUTPUT); // Blue LED for diagnostics
digitalWrite(LEDB, LOW);
if (!ModbusRTUClient.begin(BAUD_RATE, SERIAL_CONFIG)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1);
}
}
void loop() {
digitalWrite(LEDB, HIGH); // LED ON to indicate a request is being sent
Serial.print("Requesting data from slave 1, register 0x0017... ");
if (!ModbusRTUClient.requestFrom(SLAVE_ID, HOLDING_REGISTERS, WIND_DIRECTION_REG, 1)) {
digitalWrite(LEDB, LOW);
Serial.print("Error! Description: ");
Serial.println(ModbusRTUClient.lastError());
} else {
digitalWrite(LEDB, LOW);
if (ModbusRTUClient.available()) {
uint16_t value = ModbusRTUClient.read();
Serial.print("Success! Value: 0x");
Serial.println(value, HEX);
} else {
Serial.println("Request successful, but no data in response.");
}
}
delay(2000);
}
Diagnostic Steps & Results
To isolate the issue, I performed the following tests.
1. Baseline Test (R4 Works Perfectly)
-
Setup: Arduino R4 + external RS485 converter + the sensor.
-
Result: This setup works 100% correctly. I can read the wind direction from register 0x0017 without any issues.
-
Conclusion: This confirms the sensor, its Modbus parameters, and the general program logic are all correct.
2. Loopback Test on the Opta (FAILED)
-
Method: I disconnected the sensor and shorted the A(-) and B(+) terminals on the Opta with a wire. The Opta was powered by the 12V PSU.
-
Result: TEST FAILED. The Opta is unable to receive the data it sends itself. The serial monitor consistently shows ERROR! No response received.
#include <ArduinoRS485.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("--- RS-485 Loopback Test ---");
RS485.begin(9600);
}
void loop() {
Serial.print("Sending: PING...");
RS485.print("PING\n");
delay(100);
String received = "";
RS485.receive();
while (RS485.available()) {
received += (char)RS485.read();
}
RS485.noReceive();
if (received.length() > 0) {
Serial.print(" Received: ");
Serial.println(received);
} else {
Serial.println(" ERROR! No response received.");
}
delay(3000);
}
3. Opta (as Slave) vs. a known-good R4 (as Master) Test (FAILED)
-
Method: I used my working R4 setup as a Modbus Master to poll the Opta, which was configured as a Modbus Slave. All devices shared a common ground.
-
Result: TEST FAILED. The R4 master reports a Timeout. The Opta slave correctly waits for a request (confirmed on its serial monitor) but never receives it. This was tested with A/B lines in both orientations.