Thursday, July 19, 2012

Arduino talks to Java over Serial Interface

Arduino talks to Java over Serial Interface
  1. Install arduino as per normal
  2. Check that the *.dll exist in this path
    Check that the *.jar file exisit in this path
  3. Create run.bat with the following data in this format, modify the parameters to suit your computer’s path.
    This will use javac to compile java and execute from CMD.

    @set path=%path%;C:\Program Files\Java\jdk1.6.0_25\bin
set PATH=%PATH%;D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\
"C:\Program Files\Java\jdk1.6.0_25\bin\javac" -cp "D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\lib\RXTXcomm.jar"
"C:\Program Files\Java\jdk1.6.0_25\bin\java" -cp "D:\Users\s41764\Desktop\Documents\Downloads\arduino-0022\arduino-0022\lib\RXTXcomm.jar;." SerialTest

  1. Upon successful compilation by javac, the program will run and display the string send by arduino.
  2. To detect the specific character sequence and associated code handling in java, use api call String.compareTo(). Note that the serial receive is not fix number of bytes. Hence, a buffer is required to store the intended message from arduino, and then to do a string comparison.

Running the default code from
Need to change port number in java code to reflect the arduino

check out the modified code here

No comments: