Go Down

Topic: Java write bytes to Arduino (Read 266 times) previous topic - next topic

Pettter

Apr 19, 2019, 02:20 am Last Edit: Apr 19, 2019, 02:35 am by Pettter
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...
Code: [Select]

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

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


PS: There is a nice API for Java: JSerialComm (https://fazecast.github.io/jSerialComm/)



Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Pettter

#2
Apr 19, 2019, 01:56 pm Last Edit: Apr 19, 2019, 01:58 pm by Pettter
[...] 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!


Go Up