Send text to Arduino via serial port

Hi, I need to send letter to arduino via serial port, but I got only the number (i think it's called decimal value, my english is bad) and i could not convert it back to letter. It is possible to convert it, or should i use

if ( input == 116) //if I send "t"
{
    //something
}

? Thanks. (sorry for my bad english)

like this:

if ( input == 't') //if I send "t"
{
    //something
}

note the single quotes

You need to post all of your code.

IF you have something like this byte input = Serial.read(); and you want to print it as a 't' you need to "cast" the byte to a char like this Serial.println( (char) input);

Try this little sketch

void setup() {
  Serial.begin(9600);
  byte test = 116;
  char testB = 116;
  Serial.println(test);
  Serial.println((char)test);
  Serial.println(testB);
}

void loop() {

}

...R

parmanik: Hi, I need to send letter to arduino via serial port, but I got only the number (i think it's called decimal value, my english is bad) and i could not convert it back to letter. It is possible to convert it, or should i use

if ( input == 116) //if I send "t"
{
    //something
}

? Thanks. (sorry for my bad english)

The code in my calculator example shows several ways to handle serial input of characters, integers, and decimal numbers http://www.hackster.io/rayburne/scientific-calculator

Ray

Robin2: You need to post all of your code.

Ok, I first detect if serial is available, if is I put the value into int and then i convert it to string. I first was trying to convert it to text with things like this vstup = String(input, DEC);., but it didn't helped

if (Serial.available())
  {
   int input =Serial.read();
   Serial.flush();
    vstup = String(input); //vstup = Czech word for input
    odpovez(vstup); //call custom function and input converted to string as parameter
  }

And then in my custom function is part like

if ( input == 116) //if I send "t"
{
    //something
}

Rest of code is to read values from sensors and send them via serial port and it is made in Czech language. I hope it should be enought of code

Simple method of capturing a string of numeric characters and converting them into an integer.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    myservo.write(n);
    readString="";
  } 
}

parmanik:

Robin2: You need to post all of your code.

Ok, I first detect if serial is available,

I meant that you need to post the entire sketch as a single item.

If the sketch is very long and parts are irrelevant to the problem it can be a good idea to write a short sketch that just demonstrates the problem and post that.

...R