Posts: 9
Joined: Tue Nov 27, 2018 1:23 pm

Serial Communication (Javafx + JSSC)

Fri Mar 15, 2019 10:56 am


I'm trying to establish a serial communication between a Raspberry Pi 3B+ (with 2018-11-13-raspbian-stretch version) and an eval. board (Atmel SAMC21 Xplained Pro).

Both boards are physically USB cable connected.

The eval board holds data that is supposed to be transmitted continuosly to the Raspberry Pi 3B+. (infinite loop).

The Raspberry Pi 3B+ on the other end is running a (Javafx + JSSC) UI program that receives the data stream from the eval board. The incoming data is to be displayed, thus updating the displayed data.

But here is my problem:
At (Javafx) programm start data is received, but only once! Although the eval board (seems) to send data continuosly.

My Raspberry Pi seems not to fetch/receive the data. So the data on display is not updated.
(Data streams in infinitely, as it should, when I fireup minicom on my Raspberry Pi terminal, with the eval board connected to the Raspberry Pi)

Since I'm relatively new to this, so I understand that the fault can be in my code. But there is also a chance that something is missing in my Raspberry Pi setup.

So my question, before I post any code:
Do I need to install some kind of software on my Raspberry Pi in order to be able to establish a (stabile/reliable) serial communication between the two boards? If "yes", then I would be glad to know which ones (and perphaps) how to get them installed.

Thank you very much in advance for your time and for your help!

Posts: 1
Joined: Thu Mar 28, 2019 10:45 am

Re: Serial Communication (Javafx + JSSC)

Thu Mar 28, 2019 10:57 am

Need some help with Javafx + JSSC.

I'm trying to establish a serial communication between a Raspberry Pi 3B+ and an eval. board (Atmel SAMC21 Xplained Pro).

Here is a symbolic representation of my hardware setup:

Raspberry Pi 3B+ with Javafx program to display incoming data [USB]<---------->[USB] eval. board with data

(My Raspberry Pi operating under 2018-11-13-raspbian-stretch version)

Using Javafx (Eclipse Version: 2018-09 (4.9.0))and JSSC (Version 2.7.0) I've written a routine that fetches (or should continuosly fetch) data from the eval. board and display it on a UI screen that connected to the Raspberry Pi. (The Javafx UI program runs on the Raspberry Pi.)

These are the problems I'm facing:

1) At (Javafx)program start, data is sent but once to the Raspberry Pi. The displayed data is not updated, although the eval. board keeps sending data.

2) The buffer is not cleared for new data. So often only part of the data is displayed statically, (meaning incoming data is not displayed).

Have tried a few things/suggestions to solve the problem without any success.

When I fireup minicom on the Raspberry Pi terminal, the data streams in just as expected.

Anyone has an idea what I'm doing wrong? (I'm a rookie in coding).

Every nudge into the right direction would be very much appreciated! ... in-chennai ... -bangalore ... in-chennai

User avatar
Posts: 1
Joined: Tue Jun 11, 2019 7:44 am
Location: Noida, India
Contact: Website Facebook Twitter

Re: Serial Communication (Javafx + JSSC)

Tue Jun 11, 2019 7:54 am

It's a series of examples to program Java + JavaFX + jSSC(java-simple-serial-connector) on Windows 10 with NetBeans IDE. Run on Windows 10, to communicate with Arduino Board. And finally show how to remote deploy on Raspberry Pi using NetBeans IDE Remote Java SE Platform.

JavaFX + java-simple-serial-connector + Arduino

This example implement a simple Java application using java-simple-serial-connector library (jSSC) , with JavaFX user interface, send bytes to Arduino Esplora via USB.

Code: Select all

package javafx_jssc;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import jssc.SerialPort;
import jssc.SerialPortException;
import jssc.SerialPortList;

public class JavaFX_jSSC extends Application {
    ObservableList<String> portList;
    private void detectPort(){
        portList = FXCollections.observableArrayList();

        String[] serialPortNames = SerialPortList.getPortNames();
        for(String name: serialPortNames){
    public void start(Stage primaryStage) {

        final ComboBox comboBoxPorts = new ComboBox(portList);
        final TextField textFieldOut = new TextField();
        Button btnSend = new Button("Send");
        btnSend.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent t) {

                if(comboBoxPorts.getValue() != null && 
                    String stringOut = textFieldOut.getText();
                    try {
                        SerialPort serialPort = 
                            new SerialPort(comboBoxPorts.getValue().toString());                        
                    } catch (SerialPortException ex) {
                            JavaFX_jSSC.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println("No SerialPort selected!");
        VBox vBox = new VBox();
        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");

    public static void main(String[] args) {

Arduino code in Esplora side (same as in the post "Serial communication between Arduino Esplora and PC").
#include <Esplora.h>
#include <TFT.h>
#include <SPI.h>

int prevSw1 = HIGH;
int incomingByte = 0;
String charsIn = "";
char printout[20];  //max char to print: 20
void setup() {
    EsploraTFT.stroke(255,255,255);  //preset stroke color
    //Setup Serial Port with baud rate of 9600
    //indicate start
    Esplora.writeRGB(255, 255, 255);
    Esplora.writeRGB(0, 0, 0);
void loop() {
    int sw1 = Esplora.readButton(SWITCH_1);
    if(sw1 != prevSw1){
      if(sw1 == LOW){
        Serial.println("Hello from Arduino Esplora");
      prevSw1 = sw1;
    while (Serial.available()) {
      char charRead =;
    if(charsIn != ""){
      Serial.println("How are you, " + charsIn);
      charsIn.toCharArray(printout, 21);
      EsploraTFT.text(printout, 0, 10);
      charsIn = "";
More Information is available:

Return to “Java”