Serial print keyboard inputs

Hi all, trying to get a grasp on serial com with Arduino, starting simple.. Trying to print to the monitor characters I type. Code is below. Using teraterm, whatever I type is being accounted for somehow because there is a carriage return, it's just whatever was printed is blank. Selecting correct baud rate, etc, wondering what is up.. any help would be awesome. Thanks!

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

void loop() 
{
    char cmd;

    if (Serial.read() > 0);
    {
        cmd = Serial.read();
        Serial.println(cmd);
    }
}

Try

if (Serial.available() > 0)

Your first problem is that your line with if has a semicolon at the end which ends the if and hence the part between {} will be always be executed. Second problem is that the if contains a read in the condition but you discard (do not print) that data; so basically if you send 12, the first read will read the 1 and the second read will read the 2 and print that 2.

Hey thanks for the response, you are right I screwed up. Noticed that bug and deleted the ; in the Arduino client, copy and pasted to the forum from notepad++ with the ;.

Not inputting anything beyond single characters, just want to see an a if I type a.

Well thanks again, you pointed out my issue and I glanced over it. That first Serial.read was supposed to be Serial.available...

anyways moving on lol, thanks a lot for your help.

edit: plus I now see you even told me to use serial.available and I missed it.. it's late, my bad :p

It's early here, day just started ;)

Next question...

I hooked up a second Arduino to transmit characters to the original Arduino (gnd to gnd, RX to TX). Still using teraterm. First Arduino, same original code powered through USB. Second Arduino code blow, powered by a battery. What I expect would look like this (its just jibberish):

R 1 R 1 R 1 etc..

What I get looks like this:

R

J

R

J

R

J

etc..

Any ideas whats going on? Thanks again for any help.

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

void loop() 
{
        delay(1000);
        Serial.println('R');
        delay(1000);
        Serial.println('1');
}

Original code (receiver) for reference:

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

void loop() 
{
 char cmd;

 if (Serial.available() > 0);
 {
 cmd = Serial.read();
 Serial.println(cmd);
 }
}

edit: ugh, copy paste killing me tonight. That read was updated to available with what I am trying to do now. Now fixed above, issue persists..