Serial print HEX Commands with quotes does not work right

Hello everyone. I would expect that this piece of code:

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("\xAA\x62\xFE\x01\x00\x61");
  delay(400);
}

would print to a serial monitor(with HEX receive enabled) this:
AA 62 FE 01 00 61
AA 62 FE 01 00 61
AA 62 FE 01 00 61
etc...

But it does not. What it does is this:
AA 62 FE 01
AA 62 FE 01
AA 62 FE 01
etc...

It seems that Arduino understands the \x00 as a nothing,maybe? What can i do to solve this? Btw, this is a volume up RS232 command for a Samsung display monitor and Samsung monitors accept this HEX command syntax ONLY : \xAA\x62\xFE\x01\x00\x61

How is the end of a C string indicated?

Try write instead.

Edit: wait. "write" uses strlen . . .

Send the bytes with individual writes

There is a variant with a specified length.

Serial.write(buf, len);

https://www.arduino.cc/reference/en/language/functions/communication/serial/write/

So

Serial.write("\xAA\x62\xFE\x01\x00\x61", 6);

should work.

1 Like

Thank you both. It worked with both ways.