Serial Monitor Prints unreadable characters

I'm trying to read data from Makel M600 model meter with ESP32. I use RS485 and IEC 62056-21. I send command to get device identification but serial monitor prints unreadable characters.
mySerial.println("/?!<CR><LF>"); this is the command for device id,

 if (mySerial.available()) {
    String response = mySerial.readStringUntil('\n');
    Serial.println("Received: " + response);

    // Baud hızı değişikliği isteği gönderme
    if (response.startsWith("/SAT")) {
      mySerial.println("[DATA]050<CR><LF>");
    }

    // Aktif tüketim sorgusu gönderme
    if (response.startsWith("/SAT")) {
      mySerial.print("[SOH]R2[STX]1.8.0()[ETX][BCC]");
    }
  }

and this is the loop part.

The output is:
Received: ������

I'm new with ESP32 and Arduino so I hope you can help me.

Is serial begin and the serial monitor baud rates the same?

yes, it is.

Looks like the device sends raw bytes as ID instead of a number as characters.

1 Like

How can I fix this?

Did you make sure that the meter sends a newline character at the end of its response?
ESP32 and the meter are using the same character encoding?

I'm not sure about new line character. Response must be device's identification. I read meter datasheet but there is nothing about characters.

You should examine what you really get

if( mySerial.available) Serial.println(mySerial.read(), HEX);

readStringUntil('\n'); returns the received garbage anyway, even if no Newline was recognized.

2 Likes

My loop part became:

void loop() {
  if (mySerial.available()) {
    
    Serial.println(mySerial.read(), HEX);

    String response = String(mySerial.read());
    // Baud hızı değişikliği isteği gönderme
    if (response.startsWith("/SAT")) {
      mySerial.println("[ACK]050<CR><LF>");
    }

    // Aktif tüketim sorgusu gönderme
    if (response.startsWith("/SAT")) {
      mySerial.print("[SOH]R2[STX]1.8.0()[ETX][BCC]");
    }
  }
}

Everytime I run the code, it prints different like FE, E6, FFFFFFFF. Is it normal?

Whether normal or not, it's wrong.

Probably the mySerial speed is not the speed your Makel M600 is using.
No idea what that Makel is, but IEC 62056-21 has different modes, not all being ASCII, and there's a complex negotiaton phase in the communication. But this is not my knowledge, just some frightening warning.

Anyway, your current version will not work, as it reads half of the characters for your Serial log, the other half of the "characters" are transformed character by character into something like String("FF"); which is not what you want, even when you will get the correct data by the proper speed settings..

1 Like

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