UART Output data is not correct !

I am trying very simple code for UART output on ESP32. It is working but data is wrong.
You can see it in the below

Data is 0x00 but i get 0x0C on Serial2 TX pin. I also checked it via oscilloscobe.

Definitetely output is 0x0C

Do you have any idea about that problem?

****************************** Program
#define tx2 17
#define rx2 16

byte data = 0x00;

void setup() {
Serial2.begin(9600,SERIAL_8N1,rx2,tx2);
}

void loop() {
Serial2.print(data);
delay(300);
}


is that on a Nano ESP32 or just a random ESP32 ?

please correct your post and add code tags

Thank you very much Jackson. Next time i will add more details. I think i solved that problem. Print send out ASCII code. by the way it is node mcu esp32S

yes, you print the decimal representation for the value 0 encoded in ASCII. So you should see the code 0x30 or 48 in decimal, not 0x0C which is the form feed code. So not sure that's the only issue you have.

(if you want to send the byte's raw value, use Serial2.write(data);)

Please correct your first post above and add code tags around your code

1 Like

Thank you very much for you recomendations.
Yes, Serial2.write is working properly

any trouble with that simple task....

please help us maintain the forum "clean" looking.

Not doing so will get you in the "selfish demanders who do not care about the community" category for many of the helpers here, including me, and we will ignore your asks in the future....

connect GPIO 16 and 17 to form a loopback then print what you are receiving - try

#define tx2 17
#define rx2 16

byte data = 0x00;

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, rx2, tx2);
}

void loop() {
  Serial2.print(data);
  Serial2.write(data);
  delay(300);
  while (Serial2.available())
    Serial.println(Serial2.read());
}

serial monitor displays

48
0
48
0
48
0
48
0
1 Like

the post is marked solved so I'm happy for you but it still looks ugly without the code tags...

as you don't seem to be willing to fix this, welcome to my ignored list.

good luck for the future.