problem : arduino serial shown something different from the input

Hello guys,

I am kinda new to Arduino but experienced in C#/C++.

I have a problem with Serial writing and reading,the problem is what ever I enter it’s shown that arduino encode it or something ,
like when I enter:

1 it’s print :

49
10

2 it’s print :

50
10

3 it’s print :

51
10

a it’s print :

97
10

A it’s print :

65
10

I know the “val” is an int , but I just test the ‘a’ and ‘A’ as an input anyway,

and I already try to use other boards and a portable IDE software

my current version of IDE is 1.8.2
and it’s an arduino Uno board connected with USB to my pc .

this is my code for basic serial communication :

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

void loop() 
{  
  if (Serial.available() > 0){
   val = Serial.read();   
   Serial.println(val);
  }
  delay(20);
}

So I have the following questions:

  1. Why it’s doing this ! is it normal ?
  2. what is the 10 that always shown !?
  3. do I need something else to show the input if is it a characters ?

Thank you all in advance!

First. you do realize it's is a contraction for it is?

Second, The ASCII for 'A' is 65, the ASCII for '0' is 48. For someone who supposedly is "experienced" in C#/C++, I find it surprising that you don't know this. 10 is LineFeed.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

ieee488:
First. you do realize it's is a contraction for it is?

Second, The ASCII for 'A' is 65, the ASCII for '0' is 48. For someone who supposedly is "experienced" in C#/C++, I find it surprising that you don't know this. 10 is LineFeed.

I know that but ,Decimal is the default format for Serial.print() and Serial.println(),
So, why I didn't get the Decimal value !!

Hint 1: ascii table (the '10' is also in there :wink: )
Hint 2: Serial.write

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Thank you so much :slight_smile:
this was very helpful
you are the best Robin2 :slight_smile:

ieee488:
First. you do realize it's is a contraction for it is?

Second, The ASCII for 'A' is 65, the ASCII for '0' is 48. For someone who supposedly is "experienced" in C#/C++, I find it surprising that you don't know this. 10 is LineFeed.

if you can't say something useful, save the words for your self please :slight_smile:

thanks any way

TUMTUM:
if you can't say something useful, save the words for your self please :slight_smile:

thanks any way

It was useful.

Why wasn't it useful? Because you couldn't understand it? Your reply #3 is laughable as is your reply #6.