Hello,
I need to show on a cloud dashboard the position of an irrigation arm. Due to harh conditions of the weather (+45 celsius during summer and -10 during winter) I choose Arduino Opta platform. Also this is more reliable from Arduino pro, suited for outdoor. Of course I will use a metal enclosure , IP65. I have selected one of the few GPS sensors I found that can be connected to OPTA using Modbus RTU: F&F MB-GPS-1. My problem is I can't read it. I have limited experience with Modbus. Has anybody successfully read a sensor using modbus protocol and OPTA?
Sensor model:
My code is simple:
#include "thingProperties.h"
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
void setup() {
Serial.begin(9600);
delay(1500);
while (!Serial);
RS485.begin(9600, SERIAL_8N2); // Baud rate: 9600, Data bits: 8, Parity: None, Stop bits: 2
if (!ModbusRTUClient.begin(1)) { // Slave ID: 1
Serial.println("Failed to start Modbus RTU client");
while (1); }
else {
Serial.println("Modbus RTU client started successfully");
}
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(D0, OUTPUT);
pinMode(LED_D0, OUTPUT);
}
void loop() {
ArduinoCloud.update();
digitalWrite(LED_D0, HIGH);
status = 1;
delay(1000);
digitalWrite(LED_D0, LOW);
status = 0;
delay(1000);
// Send request to read discrete inputs using the 0x02 command
if (ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 1)) { // Slave ID: 1, Function Code: 0x02 (DISCRETE_INPUTS), Address: 0x00, Number of inputs: 1
int value = ModbusRTUClient.read(); // Read the value from the specified input
xStatus = value;
if (value != -1) {
Serial.print("Value read: ");
Serial.println(value);
if (value == 0) { Serial.println("GPS signal received"); }
else { Serial.println("No GPS signal"); } }
else { Serial.println("Error reading the discrete input"); } }
else { Serial.println("Failed to read from the GPS sensor"); }
}
The GPS Characteristics are:
Modbuss Address - 1
Spees - 9600
Parity - none
stop bits - 2
Works as slave
data bits: 8
registers are read with 0x03 command
Then I have a full list of addresses. Address 0x00 is read only mode and shall return 1 if GPS Signal is received correctly and 0 if not - this is what I am trying to read.
Thanks in advance!
