I'd like to use the JSerialComm library to communicate between Java and an Arduino UNO. What is the simplest way?
It's just for simple automation so I need to send just a char or an int to serial port and pick it up in the Arduino to tell it which relays to turn on.
I looked at finished online projects and came up with this. Port is COM5
chosenPort = SerialPort.getCommPort("COM5");
//chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); //dunno
chosenPort.setBaudRate(9600);
System.out.println(chosenPort.getBaudRate());
chosenPort.openPort();
System.out.println("TEST1");
try {Thread.sleep(5000); } catch(Exception e) {}
System.out.println(chosenPort.isOpen());
if(chosenPort.openPort()) {
PrintWriter output = new PrintWriter(serialPort.getOutputStream()); ETC
Sometimes the port opens, mostly it doesn't. And when it did I didn't pick up anything on Arduino serial monitor... On the sketch I made a method with
if (Serial.available() == 1) {
int serialData = Serial.read();
Serial.println(serialData);