Serial monitor is not showing the right text

I tried to modify the Physical pixel example,by coding the arduino to print the data it receives, rather then blink when it detects “L” and “H”. However, when i print the data it is written in code rather than the text i commanded it to print. For example, if I send the arduino the letter A, rather than printing the “A” it will print “65”. Please, help!

int incomingByte;       

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

  Serial.print("HI");
}

void loop() {
 
  if (Serial.available() > 0) {
    
    incomingByte = Serial.read();
    Serial.println(incomingByte);

  }
}

sketch_apr28b.ino (274 Bytes)

You've declared incomingByte to be an integer, so it is printed as an integer. Declare it to be a character:

char incomingByte;

Pete

For example, if I send the arduino the letter A, rather than printing the "A" it will print "65".

You receive the value and store it in an int. What else is it going to print?

Store the incoming byte in a char variable. Do NOT name it incomingByte.

For example, if I send the arduino the letter A, rather than printing the "A" it will print "65".

It's time for you to get acquainted with ASCII. Google is your friend.

You are putting the incoming byte into an int variable (confusingly named incomingByte even though it is an int not a byte). When you print it you are getting the ASCII code for the character entered.

Try making the variable that the data is put into a char and while you are at it give it a better name that reflects its data type.