First of all, sorry for the confusing title. I’m trying to make a simple program on my arduino that echos the serial input received from the serial monitor. My code is this:
String string= "";
String string2 = "";
void setup()
{
Serial.begin(9600);
}
void loop() {
string = "";
while(Serial.available() > 0)
{
string += (char) Serial.read();
Serial.flush();
}
if(string != "")
{
Serial.println(string);
}
}
But when I upload it and open the serial monitor, and input anything it is spread over several lines, as so:
Input: Why are you doing this?
W
hy
are y
ou doin
g this?
I’ve been stuck on this for hours now. My device is the Arduino Uno (Offical), I’m running on windows 7. Thanks in advance for any help.
Edit: Serial.print(string) returns nothing, leaves the console screen blank.
Use
Serial.print(string);instead of println()Ref: http://arduino.cc/en/Serial/Println