Java write bytes to Arduino

Hey,

I've already tried several ways to send bytes from Java to the Arduino.

Receiving bytes with Java from the Arduino works without problems.

Could someone show me an example?

The Arduino code looks like this...

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

void loop() {
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
}

PS: There is a nice API for Java: JSerialComm (jSerialComm)

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

Make sure that your Java program opens the serial port, allows time for the Arduino to reset before sending the first data and then keeps the serial port open until it is completely finished with the Arduino.

This simple Python - Arduino demo illustrates the process.

...R

Robin2:
[...] allows time for the Arduino to reset before sending the first data and then keeps the serial port open until it is completely finished with the Arduino. [...]

Thanks! How easy the error may be if you do not respect the waiting!