Reputation: 959
I was trying to send a message to Arduino (to test if the Arduino received any message the motor will turn on), the following code works if I run on Terminal
echo 1 > /dev/ttyACM0
But I tried this in Java
Runtime.getRuntime().exec("echo 1 > /dev/ttyACM0");
Anyone knows how to execute in Arduino Serial port?
Upvotes: 1
Views: 3121
Reputation: 2437
Java doesn't provide support for serial communications out of the box. You need to use a 3rd party library or extension. Oracle do provide one - Java Communications API
http://www.oracle.com/technetwork/java/index-jsp-141752.html
I have used this in the past with AVR Micro-controllers. There are several tutorials on the net to get it up and running.
Upvotes: 0
Reputation: 396
I used the RXTX lib for Java serial connections.
Very similar code to what worked for me is shown here:
https://embeddedfreak.wordpress.com/2008/08/08/how-to-open-serial-port-using-rxtx/
Upvotes: 1
Reputation: 405
Try RXTX library, this is Java wrapper for the serial port. Project website. Example: source
Upvotes: 0