Serial port read error please help

Hello. Im using serial read () command and when enter keyboard 1, see 49 50 on serial port screen.

There is no error. The Number 49 is the ASCII code for '1', and 10 is the code for newline, which is appended by the serial monitor ( you can inhibit that with a setting at the bottom of the serial monitor window )
Please don't post code and monitor output as pictures and read

before posting the next time.

1 Like

Serial monitor settings not showing.

Probably off the screen to the right because you have the Serial monitor positioned off screen to the right

When entering data from a keyboard, the data output is ASCII code for what you going to type. In order to display a number, you have to converted the ASCII code of numbers ( 0 to 9 ) into BINARY code and display the binary code.

Here the table ...

So the ASCII code from 0 to 9 is --> 0x30 to 0x39. or from B00110000 to B00111001.
So you have to remove the last upper 4 bits and isolate the lower 4 bits.

But first, you have to keep any data that is between 0x30 to 0x39, any data that is outside that range will be rejected.

Like ...
B00110101 ---> Enter ASCII 5 - you press 5 on the keyboard
B00001111 --> the Mask
B00000101 --> Binary code for 5 - Result

result = keyboard_data & the_mask;

The display --> serial.print(result, DEC);
It will display a 5

1 Like

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