I want to send text over serial monitor to Arduino and make Arduino return that string back to me over serial monitor.
I have made this function which reads from serial input and returns a string object.
String readSerial() {
String input;
while(Serial.available() > 0)
input.concat(Serial.read());
return input;
}
In the loop()
I have:
if(Serial.available()) Serial.print(readSerial());
If I just do something like Serial.print("Hello world!");
everything is fine. But, if I try to return string object I get lot's of numbers.
I guess Serial.print
doesn't know how to read String
object and returns ASCII codes of characters or something?
[update]
I have checked it, and it's indeed outputing ASCII codes. For Hi
I get 72105
.
[update]
I have updated my readSerial
function to use this :
input += (char)Serial.read();
But now I'm getting carriage return and new line after every character:
[SEND] Hi
H(CR)
i(CR)
So, how can I make it return my text so that is readable?