Controlling modbus module using ESP8266

hi!
I would like to read some data from the inputs of my modbus module, but it only give me squares in the serial monitor, is there any solution to this problem. Thanks

here is the code im using !

saisissez ou collez du code ici#include <ModbusMaster.h>

#define MAX485_DE_RE   5  // D1 ESP8266

// instantiate ModbusMaster object
ModbusMaster node;

// Fonction de gestion du mode transmission/réception
void preTransmission()
{
  digitalWrite(MAX485_DE_RE, 1);  // Activer l'émission (DE = 1, RE = 1)
}

void postTransmission()
{
  digitalWrite(MAX485_DE_RE, 0);  // Activer la réception (DE = 0, RE = 0)
}

void setup()
{
  pinMode(MAX485_DE_RE, OUTPUT);

  // Init en mode réception
  digitalWrite(MAX485_DE_RE, 0);

  // Modbus communication runs at 9600 baud sur hardware serial
  Serial.begin(9600);

  // ID d'esclave Modbus 1
  node.begin(1, Serial);

  // Définir les callbacks pour gérer le transceiver RS485
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop()
{
  GetDigitalInputs();
}

void GetDigitalInputs()
{
  uint8_t result;

  // Lecture des entrées digitales à partir du registre 1000, et lire 10 entrées
  result = node.readDiscreteInputs(1000, 10);

  if (result == node.ku8MBSuccess)
  {
    // Si la lecture est réussie, afficher les valeurs
    for (int i = 0; i < 10; i++) {
      Serial.print("Entrée ");
      Serial.print(i);
      Serial.print(": ");
      Serial.println(node.getResponseBuffer(i) ? "HIGH" : "LOW");
    }
  }
  else
  {
    // En cas d'erreur dans la lecture
    Serial.print("Erreur de lecture des registres. Code d'erreur: ");
    Serial.println(result, HEX);
  }

  delay(5000); // Délai entre les lectures
}

image

Please return and edit your first message, inserting the code using a code tags.

soory i forgot to do it !
could u help me with this problem

You are using your hardwareserial for both, serial monitor and modbus.
It doesn't work like that. Use softwareserial for modbus.
Or use Serial1 for serial monitor (you need usb-serial converter for this).

what do you mean by usb-serial converter , please explain more
what would be the solution, am using esp8266 which have two serials rx0,tx0 and rx2,tx2

However you use only one serial in the code - both for modbus and for printing.

move the modbus to second serial

It really doesn't have two, you can swap Serial from pins rx/tx0 to pins rx/tx2.
But it has tx on Serial1 (gpio2) which you could use for serial monitor.

But why to bother, if your device use 9600 bps, softwareserial works great.

if you could just regenrate the lines i should change i would be grateful; im really stuck at this point

gpio pins 4,5 and 12

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

// Define software serial RX and TX pins
#define RX_PIN 4
#define TX_PIN 5

#define MAX485_DE_RE 12


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

ModbusMaster node;

// Fonction de gestion du mode transmission/réception
void preTransmission()
{
  digitalWrite(MAX485_DE_RE, 1);  // Activer l'émission (DE = 1, RE = 1)
}

void postTransmission()
{
  digitalWrite(MAX485_DE_RE, 0);  // Activer la réception (DE = 0, RE = 0)
}


void setup()
{
  pinMode(MAX485_DE_RE, OUTPUT);
  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);
  }