ESP32 with Rs232 to scale

Hello!

Im newbie and im encountering a strange problem that i cant solve.

Im trying connect a esp32 to a loader with RS232 to TTL converter.

Its a master and slave system, where the esp32 sends a command to the scale and it must return the value that is being weighed.

I simplified the code to be able to test better:

#include <HardwareSerial.h>

#define RXD2 16
#define TXD2 17

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);

  Serial.println("Iniciando comunicação...");
}

void enviarComandoSerial2() {

  const char* comando = "01P\r\n";

  Serial2.write(comando);

  Serial.print("Comando Enviado: ");
  Serial.print(comando);
  Serial.println();

  Serial2.flush();

}

void loop() {

  enviarComandoSerial2();

  String recebidoSerial2 = "";
  unsigned long startTime = millis();
  while (millis() - startTime < 2000) { 
    while (Serial2.available() > 0) {
      char c = Serial2.read();
      recebidoSerial2 += c;
    }
  }

  if (recebidoSerial2.length() > 0) {
    Serial.print("Recebido na Serial2: ");
    Serial.println(recebidoSerial2);
  } else {
    Serial.println("Nenhuma resposta válida recebida.");
  }
  delay(2000);
}

The strange thing that happens is that when I connect the RS232 converter to the computer using an RS232 to USB cable, I can see the command being sent by ESP at the cable terminal.

When I connect the scale to the computer via the converter cable, and send the command 01P+Enter, it is possible to see the scale responding to the measured value.

But when I connect the ESP32 + Rs232 Converter to the scale, nothing happens.

Has anyone gone through something similar?

Hi @fiorotti ,

Welcome to the forum..

pretty sure, that will just send 1 byte..
try this..

Serial2.write(comando,strlen(comando));

good luck.. ~q

Serial2.println("01P");