On my Arduino UNO the example here http://playground.arduino.cc/Interfacing/Java works just fine.
Here is my Arduino Code:
void setup() {
Serial.begin(9600);
//Serial1.begin(9600);
}
void loop() {
Serial.println("ping");
//Serial1.println("ping1");
delay(1000);
}
The Java code is the same as in the example. I only changed the PORT_NAMES variable to the COM Port of the Uno (in my case it's COM7).
If I upload the code and run the Java program, I get the following output:
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
trying to connect to port COM7
Started
ping
ping
...
Which is what I expected.
However, if I upload the code to the Leonardo the Java program apparently does not receive any messages. I have changed the PORT_NAMES variable to the COM Port of the Leonardo (COM9). I even tried to uncomment the lines that use Serial1. I can however, receive data sent from the Java program to the Leonardo.
I noticed that if I send data from the Java program to the Leonardo, the RX led blinks. However, if I send data from the Leonardo RX and TX leds are off.
Why does sending data from the UNO to the PC work, but not from the Leonardo?