Arduino OPTA and Modbus Connection

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!

I'm not familiar with your board, neither the libraries you use.
Since slave address is given in request, I doubt you should give it as parameter for .begin.
ModbusRTUClient.begin(9600, SERIAL_8E2) looks more correct.
Did you try with library examples?

I have tried with the library examples and still without success. Maybe I am doing some connection wrong?

I see opta is using A- / B+ scheme which is technically correct. But many devices are using A+ / B-, I didn't find info about yours .
You could swap the wires to try, chances are high your main issue is here.

Hello! I have tried this already. I have just wrote an email to GPS technical support company to ask for guidance.

Ciao,
a parer mio mancano i tempi di attesa prima e dopo l'invito a trasmettere

constexpr auto baudrate { 9600 };                           // velocità Modbus
constexpr auto btime { 1.0f / baudrate };                 // Valore per il calcolo dei tempi di attesa
constexpr auto predl { btime * 9.6f * 3.5f * 1e6 };   // tempo di attesa prima della trasmissione
constexpr auto postdl { btime * 9.6f * 3.5f * 1e6 };  // tempo di attesa dopo la trasmissione
....
....
void setup() {
    RS485.setDelays(predl, postdl);  
......

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.