I need to send serial data to my Arduino UNO from within a java application. I am using JSSC for this.
I wanted to verify that my data actually arrives correctly to the arduino before going to the next step of my application. For this I tried to just return the string I am sending, however when I send "test", this is what is returned:
t
null
est
I am wondering if this is a problem on the Java side with sending/reading the string, or that it's a problem with sending/reading on the arduino, and how I could possibly fix this.
This is my java code to read the data:
try {
port.addEventListener(event -> {
try {
System.out.println(port.readString());
} catch (SerialPortException e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
}
This is my java code to send the data:
try {
port.writeString("test");
} catch (SerialPortException e) {
e.printStackTrace();
}
And this is the code on my arduino:
void loop() {
while (Serial.available() > 0) {
Serial.print(Serial.readString());
}
}
I hope someone can help :)