Skip to main content
Minor fixes
Source Link
Greenonline
  • 3.2k
  • 7
  • 37
  • 49

java Java + jsscJSSC + arduinoArduino + windowsWindows

I want to know the basics of arduinoArduino serial comunicationscommunications and connection with a javaJava application in windowsWindows.

Can anybody provide me with a sample javaJava program that on runupon running just makes an arduinoArduino pin high as well as the according arduinocorresponding Arduino sketch

 , and some explenationexplanation on how the arduino comunicatesArduino communicates with the javaJava app?

I am now starting with arduinoArduino,

  and I have some experience with javaJava

I found this code on the net - will this work?

JAVA CODEJava code

 package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

public static void main(String[] args) throws InterruptedException {

    SerialPort serialPort = new SerialPort("COM3");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("o".getBytes()));
        Thread.sleep(1000);
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("f".getBytes()));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }
  }
}

ARDUINOArduino

java + jssc + arduino + windows

I want to know the basics of arduino serial comunications and connection with a java application in windows

Can anybody provide me with a sample java program that on run just makes an arduino pin high as well as the according arduino sketch

  and some explenation on how the arduino comunicates with the java app

I am now starting with arduino,

  I have some experience with java

found this code on the net will this work?

JAVA CODE

 package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

public static void main(String[] args) throws InterruptedException {

    SerialPort serialPort = new SerialPort("COM3");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("o".getBytes()));
        Thread.sleep(1000);
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("f".getBytes()));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }
  }
}

ARDUINO

Java + JSSC + Arduino + Windows

I want to know the basics of Arduino serial communications and connection with a Java application in Windows.

Can anybody provide me with a sample Java program that upon running just makes an Arduino pin high as well as the corresponding Arduino sketch, and some explanation on how the Arduino communicates with the Java app?

I am now starting with Arduino, and I have some experience with Java

I found this code on the net - will this work?

Java code

package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

public static void main(String[] args) throws InterruptedException {

    SerialPort serialPort = new SerialPort("COM3");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("o".getBytes()));
        Thread.sleep(1000);
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("f".getBytes()));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }
  }
}

Arduino

added 1711 characters in body
Source Link
AXANO
  • 111
  • 1
  • 6

found this code on the net will this work?

JAVA CODE

 package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

public static void main(String[] args) throws InterruptedException {

    SerialPort serialPort = new SerialPort("COM3");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("o".getBytes()));
        Thread.sleep(1000);
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("f".getBytes()));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }
  }
}

ARDUINO

  void setup()   {                
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  digitalWrite(8,HIGH);
  delay(500);
  digitalWrite(8,LOW);
  }

  int incomingByte = 0;

  void loop()                     
  {
 // send data only when you receive data:
    if (Serial.available() > 0) {
           int text = Serial.read();
           Serial.println(text);
           if (text == 'o') {
            
            digitalWrite(8,HIGH);
             
           }
           
           if (text = 'f') {
            
            digitalWrite(8,LOW);
             
           }
     }

  }

found this code on the net will this work?

JAVA CODE

 package arduino;

import jssc.SerialPort;
import jssc.SerialPortException;

public class Arduino {

public static void main(String[] args) throws InterruptedException {

    SerialPort serialPort = new SerialPort("COM3");
    try {
        System.out.println("Port opened: " + serialPort.openPort());
        System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("o".getBytes()));
        Thread.sleep(1000);
        System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("f".getBytes()));
        System.out.println("Port closed: " + serialPort.closePort());
    } catch (SerialPortException ex) {
        System.out.println(ex);
    }
  }
}

ARDUINO

  void setup()   {                
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  digitalWrite(8,HIGH);
  delay(500);
  digitalWrite(8,LOW);
  }

  int incomingByte = 0;

  void loop()                     
  {
 // send data only when you receive data:
    if (Serial.available() > 0) {
           int text = Serial.read();
           Serial.println(text);
           if (text == 'o') {
            
            digitalWrite(8,HIGH);
             
           }
           
           if (text = 'f') {
            
            digitalWrite(8,LOW);
             
           }
     }

  }
Source Link
AXANO
  • 111
  • 1
  • 6

java + jssc + arduino + windows

I want to know the basics of arduino serial comunications and connection with a java application in windows

Can anybody provide me with a sample java program that on run just makes an arduino pin high as well as the according arduino sketch

and some explenation on how the arduino comunicates with the java app

I am now starting with arduino,

I have some experience with java