Hi, I have the following problem and I've been looking for examples on the web for a long time but none seems to work for me.
I would like to know how to read the values of the Schneider PM800 controller via RS-485 ModBus on my ESP32.
I have the following:
#include <ModbusMaster.h>
#include <HardwareSerial.h>
#define RS485_DE_RE_PIN 2
#define RS485_RX_PIN 16
#define RS485_TX_PIN 17
// Crear un objeto Modbus
ModbusMaster node;
void setup() {
// Inicializar el puerto serie para la comunicación RS485
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN);
// Configurar el pin de habilitación (DE/RE) como salida
pinMode(RS485_DE_RE_PIN, OUTPUT);
// Iniciar la comunicación Modbus
node.begin(1, Serial1); // Dirección del dispositivo y objeto Serial1
// Iniciar en el modo de recepción
digitalWrite(RS485_DE_RE_PIN, LOW);
}
void loop() {
// Cambiar al modo de transmisión
digitalWrite(RS485_DE_RE_PIN, HIGH);
delayMicroseconds(500); // Esperar un tiempo para la estabilización del bus
// Leer registros del controlador PM800
uint8_t result = node.readInputRegisters(0x10, 2); // Dirección del registro y número de registros a leer
// Cambiar al modo de recepción
digitalWrite(RS485_DE_RE_PIN, LOW);
delay(1000); // Esperar antes de la siguiente lectura
// Verificar si la lectura fue exitosa
if (result == node.ku8MBSuccess) {
// Obtener los valores leídos
uint16_t value1 = node.getResponseBuffer(0);
uint16_t value2 = node.getResponseBuffer(1);
// Hacer algo con los valores leídos
// ...
// Imprimir los valores en el monitor serie
Serial.print("Valor 1: ");
Serial.println(value1);
Serial.print("Valor 2: ");
Serial.println(value2);
} else {
// Hubo un error en la lectura
Serial.print("Error de lectura: ");
Serial.println(result);
}
}
I need guidance with this, thank you very much.


