ModBus question

Good day !

I have a XY-MD02 (temperature + humidity over RS-485)

using an RFRobot USB to RS485 converter, I was able to validate that the sensor is at address 1, 9600 baud and that register 0x02 & 0x03 holds the temperature + humidity (despite being 0x01 & 0x02 according to the datasheet)

I haven't been able to talk to it with a Nano... I using a MAX485 based converter (the one that has DI, DE, RE and RO)

I have tried numerous libraries (ModbusMaster, ModbusArduino, ArduinoModBus, Modbus-RTU, Modbus-ESP8266) without any luck...

Has someone with the same hardware succeded?

If so, can you provide the wiring diagram used, as well as the exact library used and the sketch that worked !?!

I'm normally fairly good with Arduino, but this one has me struggling....

TIA

Try with this

//use Modbusmaster library by Doc Walker

#include <ModbusMaster.h>
#include <SoftwareSerial.h>

// Define software serial RX and TX pins
#define RX_PIN 2
#define TX_PIN 3

#define MAX485_DE_RE 4

// Create a SoftwareSerial instance
SoftwareSerial mySerial(RX_PIN, TX_PIN);

ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_DE_RE, 1); 
 }

void postTransmission()
{
  digitalWrite(MAX485_DE_RE, 0); 
  }

void setup()
{
  pinMode(MAX485_DE_RE, OUTPUT);
  digitalWrite(MAX485_DE_RE, 0);
  Serial.begin(9600);
  mySerial.begin(9600); // Initialize software serial port
  node.begin(1, mySerial); // Use software serial for Modbus communication
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop()
{
  uint8_t result;
  uint8_t j;
  result = node.readInputRegisters(0x0001, 2);
  if (result == node.ku8MBSuccess)
  {
  for (j = 0; j < 2; j++)
  {
  Serial.println(node.getResponseBuffer(j));
  }
  } 
  else 
  {
    Serial.print("Modbus Error: ");
    Serial.println(result);
  }

  delay(2000);
}

Make sure your wiring is rock solid.
Rx to RO, Tx to DI, DE and RE bridged together.