Serial communication ASCII not recognized by terminal

Hello,

I'm trying to put into operation my serial1 communication. I have used this small code:

void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.print(0);
  delay(1000);
}

On the terminal I don't get the value "0x00" (if looking directly to the hexadecimal value) every 1000ms but the value 0x06:

9F 00 06 06 06 06 06 06

If I change the code to Serial1.print(1), I get 0x67 and with Serial1.print(2) I get 0x33.

I don't understand where the Problem is. Which setting do I have to change?

How do you have the Arduino connected to the computer? Are you using a serial port or USB-to-RS232 converter? Neither of those will work without a level shifter to convert RS232 voltages to TTL voltages (RS232 and TTL have inverted logic, and RS232 has larger voltages than you should connect directly to an Arduino).

If you are using a level shifter or a USB-to-TTL converter, I don't see why it wouldn't work.

Thanks for the reply. I was using an USB to RS-232 converter. :roll_eyes:

Hi,
It appears you are connecting a TTL serial port to an RS232 compatible port. Thus serial data displayed is "inverted".

If that is the case then you need to add an inverter somewhere in the signal paths. In both Rx and Tx lines for bi-directional communication, or just the Tx line to the terminal if you just want to monitor output.

The ASCII code for 2 is 0x32 = 0110010 in binary

The 0x33 you are seeing is = 00110011

This does not look like an inversion but the start and stop bits are also inverted so the data or stop bits get detected as start bits and hence the terminal does not find the start of the inverted ASCII value correctly.

The other possibility is that the baud rates do not match between the Arduino and the terminal, or the format at the terminal is not set to 8N1 (Arduino default).

If you cannot solve the problem based on the above then we will need a more detailed description of your setup.