Java grapher for Arduino serial monitor


Seeing as I had now got Eclipse IDE running for Java and Arduino, see Eclipse for Arduino, I decided to first tackle a simple GUI test application and then the Java Graphing application for the Arduino serial monitor, as outlined by upgrdman‘s excellent videos. These were simple enough to do.

Finally, this morphed into upgrdman‘s (way more sophisticated) TelemetryViewer, which took me three attempts and a week to get running…


This blog outlines the setup of four upgrdman Java applications in Eclipse (on OS X):

  1. A simple slider GUI test application – Slider
  2. A basic graphing application – SensorGraph
  3. A sophisticated TelemetryViewer application
  4. PC to Arduino communication – Arduino LCD Clock

Note: I noticed that there was no set default action of closing the window to quit the app, in SensorGraph nor LCD Clock, which was required in the Swing application described in Java and NetBeans on OS X.


These are links to upgrdman videos:


  • Java SE JDK (8u31) – either via Oracle, or for OS X, use HomeBrew (see below)
  • Eclipse IDE for Java Developers (Luna SR1) 64 bit
  • Library SerialComm v0.9, now called jSerialComm v2.6.2
  • Library JFreeChart v1.0.19 – for the second graphing application only
  • TelemetryViewer source code and JAR files – for the third TelemetryViewer application

Installing Java

For OS X I have found that Oracle have made things not so easy, so it is easier to use HomeBrew. From How to install Java 8 on Mac,

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8

The above commands worked, although I did get this warning

Warning: Calling brew cask install is deprecated! Use brew install [--cask] instead.

First test Java GUI application (Slider)

Arduino Sketch

Examples> Basics> AnalogueReadSerial


  Reads an analog input on pin 0, prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  delay(1);        // delay in between reads for stability

Java application

Creating the Java project is straightforward, just watch the video.

You will need to add the JSerialComm JAR file. Right click the project, >Build Path> Configure Build Path>Libraries tab>Add External JARs button.

Right click project>New> Class. Name the class. Click the public static void main(String[] args) stub checkbox.

This is the final code from the video:

 * See video: Serial Communication Between an Arduino and a PC with Java
 * URL:
 * */

import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JSlider;

// import j.extensions.comm.*; /* from video */
// import com.fazecast.jSerialComm.*;
import com.fazecast.jSerialComm.SerialPort; /* new import method */

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame windows = new JFrame();
		JSlider slider = new JSlider();

//		SerialComm ports[] - SerialComm.getCommPorts(); /* from video */
//		jSerialComm ports[] - jSerialComm.getCommPorts();
		SerialPort ports[] = SerialPort.getCommPorts();
		//Get user to select port
		// TODO: Should be a UI
		System.out.println("Select a port: ");
		int i = 1;
		for (SerialPort port : ports) {
			System.out.println(i++ + ". " +port.getSystemPortName());
		Scanner s = new Scanner(;
		int chosenPort = s.nextInt();
		// Open port
		SerialPort port = ports[chosenPort - 1];
		if (port.openPort()) {
			System.out.println("Successfully opened the port.");
		} else {
			System.out.println("Failed to open the port.");
		// Set timeouts
//		port.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
		port.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); // As per the video comments
		// Read the input port
		Scanner data = new Scanner(port.getInputStream());
		// Display port input
		int number = 0;
		while (data.hasNextLine()) {
			try{ number = Integer.parseInt(data.nextLine());}catch(Exception e) {}


The Java application is complete, but with a few issues:

  1. Variable s gives a warning that it is never closed: “Resource leak: ‘s’ is never closed”. However, the Scanner data doesn’t give a similar warning, I’m not sure why.
  2. The port selection should be as a UI element.
  3. The application may never close – add this line at the top, after the window definition: window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Issue 1 can be fixed with

	 Scanner s = new Scanner(;
	 int chosenPort = 0;
		try {
		   chosenPort = s.nextInt();
		} finally {

from Resource leak: ‘scanner’ is never closed.

Even better still, this answer to Scanner is never closed mentions the The try-with-resources Statement:

try(Scanner scanner = new Scanner({
    //rest of your code

The try-with-resources statement ensures that each resource is closed at the end of the statement.

The updated code from the video is here,

import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JSlider;
import com.fazecast.jSerialComm.*;

public class Main {

	public static void main(String[] args) {

		JFrame window = new JFrame();
		JSlider slider = new JSlider();

		SerialPort[] ports = SerialPort.getCommPorts();
		System.out.println("Select a port:");
		int i = 1;
		for(SerialPort port : ports)
			System.out.println(i++ +  ": " + port.getSystemPortName());
		Scanner s = new Scanner(;
		int chosenPort = s.nextInt();

		SerialPort serialPort = ports[chosenPort - 1];
			System.out.println("Port opened successfully.");
		else {
			System.out.println("Unable to open the port.");
		//serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY);
		serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);

		Scanner data = new Scanner(serialPort.getInputStream());
		int value = 0;
			try{value = Integer.parseInt(data.nextLine());}catch(Exception e){}


The second Java Graphing application

Arduino Sketch

Change Examples> Basics> AnalogueReadSerial delay() from 1 to 1000 (i.e. 1 second).

Java application

You will need to add the JSerialComm, JFreeChart and JCommon JAR files. Right click the project, >Build Path> Configure Build Path>Libraries tab>Add External JARs button

Right click project>New> Class. Name the class. Click the public static void main(String[] args) stub checkbox.

A few annoying bugs

Note: If you have multiple projects, you may find that the wrong project runs, when you hit compile. For example, even though I had started writing the Java Graph, I found that the Slider application opened when I hit compile.

Solution is to close the unused projects. You can right click on the old project and select Close Project. But compile will now give an error, saying “mains references a closed project”.

I then right clicked the project and selected Run As> “1 Java Application”, but while that got rid of the error, the Window didn’t appear. I also got the following messages in the console:

Listing the various classloaders:
Defined classloader source: ThreadContext
User classloader: null
Classloader for ObjectUtilities.class: sun.misc.Launcher$AppClassLoader@33909752
Classloader for String.class: sun.misc.Launcher$AppClassLoader@33909752
Thread-Context Classloader: sun.misc.Launcher$AppClassLoader@33909752
Defined System classloader: sun.misc.Launcher$AppClassLoader@33909752

Listing sources for '/':

Listing sources for 'org/jfree/JCommonInfo.class':

I think these messages were due to the fact that I had the ClassPathDebugger selected inadvertently, in the Run As dialog:

If you select, Sensor Graph (default package) then the console messages do not appear – in the same way as right clicking the main class window (below next).

Right click the main class window, and select Run As and the console messages disappear, but the window still doesn’t appear.

To fix the no window showing issue, I found that I had added jfreechart-1.0.19-swt.jar instead of jfreechart-1.0.19.jar. The swt causes an issue on OS X.


  1. How do you switch projects? – close project;
  2. Eclipse will only run first program HelloWorld  – Run as, and;
  3. Java JFrame Window not appearing when run from Eclipse – no JFrame showing due to swt.

The next issue I had was at ChartFactory. Apparently there was no JavaDoc and so it would not suggest any methods. Although, it did suggest in the end, after hovering over a partially typed “createXYLine”, but with four null as parameters (not (title, xAxisLabel, yAxisLabel, dataset)).

The next issue was at AddActionListener, I had two lines of red code. I couldn’t see the error. After going to the autofix and pasting in the expected lines (which looked identical) it worked fine.

Exporting as Runnable JAR file

Right click project>Export…>Java>Runnable JAR file>Next>Select Project> Save Location>select Package required libraries in generated JAR>Finish.

The third TelemetryViewer application

Note: this is a bit more of a tricky nut to crack.

Unzip the downloaded zip file from TelemetryViewer source code and JAR files, I used v0.7 (, but apparently there is an issue with it on OS X. However, v0.6 ( works correctly (but not with the JOGL files from 0.7 src zip.).

Create new Java project

Then I dragged all the files in the lib directory in the zip to the lib folder into the project GUI, and did the same with the files in the src and the metadata directories.

But it won’t compile, main() has a problem with the OpenGLChartsView not being defined (and animator). The opengl source files are in the If you unzip it, you can see the .java files.

Right click the project folder and select Build Paths>Add External Archives to import the archive for the, and this ended up under Referenced Libraries folder.

Once imported the dot paths are recognised from the directory structure. However the .java files within those directories are not showing up in the project.

This guide shows how to add jogamp to Eclipse: Setting up a JogAmp project in your favorite IDEEclipse IDE user library. However this is for JAR files. I have .java files in [Edit – as is seen later, this was a confusion on my part].

It doesn’t seem possible to remove the referenced library and start all over again. Apart from Build Path>Configure Build Path>Libraries tab> Remove. Or right click under Referenced Libraries and select Build Path>Remove from build Path

I did that.

Then I tried import>General>Archive File and this spewed the contents of the zip all in the project folder and created “com”, “java” jogamp”, “native” and “net” folders at the top level (these are the same as the folders inside the zip). This isn’t the way to do it. Right clicking and selecting Delete, removed these folders

However, I noticed that is actually in the src folder already…! So why isn’t main() seeing it? has a problem with the Animator class at the top of the file, which is defined in com.jogamp.opengl.util.Animator, and the import com.jogamp.opengl.* statements at the top aren’t being resolved.

Solution: So then I dragged the unzipped jogamp-fat-java-src directory from the finder to the project folder, so that it showed at the top level (alongside src), right click and Build Path>Use as source folder. This fixed the unresolved import com.jogamp.opengl.* statements.

Remaining issues: import org.eclipse.swt.* statements unresolved in jogamp/opengl/swt/ You need the Eclipse SWT source. Download, Unzip this file (to get swt.jar), Build Path>Add External Archives (or Configure Build Path), add the swt.jar. Now the import org.eclipse.swt.* statements are resolved.

Now, the import org.eclipse.jetty statements unresolved in ????. Download jetty. unzip Build Path>Add External Archive , add the start.jar. This didn’t help.

Or didn’t it..? Now the error message has changed to  org.eclipse.jetty.websocket unresolved. Adding jetty-webapp-9.4.35.v20201120.jar didn’t help.

How about adding the whole zip file? Remove start.jar and the jetty-webapp-9.4.35.v20201120.jar. Right click project, Build Paths>Add External Archives, select This didn’t help – we are back to org.eclipse.jetty statements unresolved. Apparently importing zips doesn’t work, see Importing zip file as library – Eclipse Java.

Delving deeper, these are the unresolved types:

WebSocket cannot be resolved to a type
WebSocketClient cannot be resolved to a type
Session cannot be resolved to a type
ClientUpgradeRequest cannot be resolved to a type
OnWebSocketConnect cannot be resolved to a type

I tried dragging the whole unzipped jetty-distribution-9.4.35.v20201120 folder to the project. Right click and Build paths> Use as source folder. Nope this doesn’t work either.

Apparently start.jar appearing to help is a red herring. This answer to Can’t find Jetty WebSocket classes after adding the libraries in classpath states:

The JARs you need are in the ${jetty.dist}/lib/websockets/ directory.

[joakim@lapetus jetty-distribution-9.0.4.v20130625]$ ls -1 lib/websocket/

Adding all five as External JARs fixed almost al of the errors. Note: These are included in the TelemetryViewer download lib folder.

New Issue: org.eclipse.jetty.util.component.ContainerLifeCycle cannot be resolved. Added jetty-util-9.4.35.v20201120.jar, then jetty-io-9.4.35.v20201120.jar, then jetty-client-9.4.35.v20201120.jar, then jetty-http-9.4.35.v20201120.jar. Note: These too are included in the TelemetryViewer download lib folder.

Adding all of these JAR files almost got the project working. lead to issue:

WARN:oejwce.JettyAnnotatedEventDriver:WebSocketClient@1651191114-12: Unable to report throwable to websocket (no @OnWebSocketError handler declared): LogitechSmoothScrolling Connection refused

New issue: Unable to open OpenGL context. I added gluegen-rt.jar and gluegen-rt-natives-macosx-universal,jar but got the same issue:

2020-12-09 21:07:08.325   [FAILURE]   Unable to create the OpenGL context.

This may be due to a graphics driver problem, or an outdated graphics card.

"Can't load library: /Users/macbook/eclipse-workspace/TelemetryViewer/natives/macosx-universal//gluegen_rt

Additional issue: import net.miginfocom.swing.MigLayout; in (amongst other files) is unresolved. Need to download, from, miglayout-4.0-swing.jar and add as external JAR. Note: This is included in the TelemetryViewer download lib folder

Another issue: For you need to add external JAR, jSerialComm-2.6.2.jar. Note: This is included in the TelemetryViewer download lib folder

Conclusion of first attempt

I think that putting all of the JAR files under the /project/lib folder, means that the JAR files are not seen nor used (correctly), as it also contains the websocket JAR files too. In fact, every JAR file that I downloaded and added is already included in the TelemetryViewer download.. Maybe using everything in the lib folder as External JAR libraries, so that they appear under /project/Referenced Libraries, might make everything work (a lot more smoothly).

It is time to start again.

Starting from scratch

  • Create a new Java project
  • Unzip the downloaded zip file from TelemetryViewer source code and JAR files.
  • Copy src contents to /project/src in the IDE
  • Copy resources to /project/resources in the IDE
  • Right click the Project, Build path>Configure Build Path>Libraries tab>Add External JARs> select everything in the lib folder
  • Drag the jogamp-fat-java-src folder to project. right click and build path>Use a source folder. MAYBE NOT REQUIRED – ignore this step

I get this error only:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /Users/macbook/eclipse-workspace/TelemetryViewer-mgj/natives/macosx-universal//gluegen_rt

Tis error is because the Native Library Location fields haven’t been defined for the JAR files in the libraries (User or External).

As a side note, the lib is called libgluegen_rt.dyib not gluegen_rt (as it is in Windows, although all Linux libs are also called libgluegen). [Edit – This isn’t important though].

See JogAmp gluegen-rt can’t find native library.

See also this answer to JOGL libraries can’t load libraries but they’re in the referenced libraries folder. It all seems to come back to Setting up a JogAmp project in your favorite IDEEclipse IDE user library.

You don’t need to create a user library called JOGL, if you have added the JAR files as External Libraries. In the Build Paths>Configure Build Path, expand the native libs (gluegen-rt-natives-*-*.jar and jogl-all-natives-*-*.jar) and specify Native Library Location. You can also expand the gluegen_rt.jar (and jogl-all.jar) and specify Native Library Location (should be the same as the native path – they are all in the same folder), although it is not clear whether this is actually necessary.

You can specify the JavaDoc Location and Source attachment (using the respective and files) for the non-native jar files too, gluegen_rt.jar and jogl-all.jar. Note that the gluegen-* is missing. Raised issue as Version 0.7 – missing from lib #44.

You can now remove the three zip files (, and from the External Library, as these are referred to in the fields beneath the expanded JAR files. Note that the gluegen-* is missing.

This enables the gluegen_rt path to be found.

Now the error is

Exception in thread "main" java.lang.NoClassDefFoundError: com/jogamp/openal/JoalVersion
at jogamp.opengl.openal.av.ALDummyUsage.main(
Caused by: java.lang.ClassNotFoundException: com.jogamp.openal.JoalVersion
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 1 more

See Having trouble running code in Eclipse using JOGL:

Actually, your code uses JOAL too, you need to put joal.jar into your classpath (Build path in Eclipse) and you need to put the JAR(s) containing its native libraries into the same directory as you did for JOGL and GlueGen.

Maybe you do need to create JOAL, after all..? The downloaded package seems to be missing joal.jar. However, there is the source file jogamp-fat-java-src/com/java/openal in the

Or maybe you should make the separate JOGL user library, rather than including it as I have, from Jogamp forum – Mac OSX 10.9 Jogl Eclipse Problem please help:

If you don’t try to build JOGL or to run ALDummyUsage, you shouldn’t get this error. If you put your own class into a separate project depending on JOGL as a user library, it should work. I have already used JOGL 2 under Mac OS X in Eclipse Kepler without trouble. In my humble opinion, you can get this kind of error when trying to build JOGL without JOAL. For example, my own project works correctly under Mac

Conclusion of second attempt

This is it! When you include the gluegen* and jogl* JAR files in the Referenced Libraries, then the ALDummyUsage runs, and you get the JOAL exception. If you put the gluegen* and jogl* JAR files in a separate User Library and then add that to your project, you will not get the JOAL exception.

Starting from scratch (for a third and final (?) time)

  • Create a new Java project
  • Unzip the downloaded zip file from TelemetryViewer source code and JAR files.
  • Copy src contents to project src folder
  • Copy resources to project folder
  • Right click the Project, Build path>Configure Build Path>Libraries tab>Add External JARs> select everything in the lib folder EXCEPT the gluegen* and jogl* JAR files
  • Create the JOGL User Library as described in Setting up a JogAmp project in your favorite IDEEclipse IDE user library, and add the gluegen* and jogl* JAR files, specify the Native Library Locations, the source zip and the JavaDoc zip files, etc.
  • Right click the Project, Build path>Add Libraries…>User Library>Next>Add the JOGL User Library you just created ( his will now appear top level and not under Reference Libraries)
  • Run

It now compiles and runs!

Additional runtime issue – and workaround

The window opens. However, I just get a blank window and a spinning apple wait disc. Initially I thought that this may be because I have nothing connected to the serial port.

However, this seems to be a issue with v0.7, or rather the updated version of the OpenGL (JAR) files used in v0.7, see Version 0.7 hangs at startup on macOS High Sierra (10.13.6) #40. The OpenGL JAR files included in v0.6 src zip do not have this issue. I get the same issue using v0.6 src with the JOAL from v0.7 src zip.

If you use the JOAL from the v0.6 src zip with the v0.6 src, it works correctly.

If you use the JOAL from the v0.6 src zip with the v0.7 src, it works correctly. So this is a workaround.

Note: The jogamp/gluegen files from v0.6 (  include both Sorce and JavaDoc zips for both jogl and gluegen.

Error (problem) in the Java code

I noticed this problem (as opposed to a compile error):

Description Resource Path Location Type
Unlikely argument type for equals(): String seems to be unrelated to JComboBox<String> /TelemetryViewer-mgj2/src line 243 Java Problem

in line 243 in


Why this is a problem, rather than a compile error, is explained in this answer to Elegant way to overcome Unlikely argument type for equals(): Stream<String> seems to be unrelated to String. See also Unlikely argument type String for contains(Object) on a Collection<String[]>.

The solution is, I think, that the line should be:


Now the types are the same and the problem warning message goes away.

I have raised an issue, Problem in – Unlikely argument type for equals(): String seems to be unrelated to JComboBox<String> #43

More portable JOGL code – using Eclipse project instead of User Library

To make the code even more portable between platforms, it is better to put the JOGL into a separate Eclipse project, see Setting up a JogAmp project in your favorite IDEEclipse IDE project.

Note: I downloaded the latest complete Jogamp code, instead of using the jogamp included with the TelemetryViewer. After unzipping the jogamp-all-platforms.7z file, I noticed that in the jar directory, there is also an “atomic” directory, containing similarly named files, all of which are considerably smaller than their counterparts in the jar folder. However, it is possible to ignore the atomic folder, as it doesn’t contain the jogl-all-* nor the gluegen-rt-* files, that are used by the TelemetryViewer.

Create a new folder to make a subset of these files for your JOGL User Library.

Copy over jogl-all-* nor the gluegen-rt-* files.

Also copy over and

Note that the JavaDoc files and are missing from the downloaded the jogamp-all-platforms.7z file. These can be downloaded separately, from the same location, as gluegen-javadoc.7z and jogl-javadoc.7z. However, it is unclear whether they will need to be converted to ZIP format before being pointed to as the JavaDoc locations for the respective JAR files. See section, Converting .7z to .zip, below to do this.

There should be 74 files in total.

Create JOAL_ALL in workspace, and copy over the 74 files.

New Java Project, name JOAL_ALL>Next>Libraries tab> remove all native JARs

You should have this:

NOTE: There may be no need for the *android* and *mobile* and *noawt* JAR files.

Expand all and add the corresponding Source Attachments.

Click the “Order and Export” tab. Check both JOGL JARs, then click “Finish”.

Now to add to your project, you right click the project>Properties>Java Build Path>Project tab>Add… button> Select the project>Apply and Close


  1. You add the library in a different way, when it is a Project rather than a User Library. Under Properties>Java Build Path, you use the Project tab, not (as you do for the User Library) the Libraries tab>Add Library…>User Library>Select the User Library (although it doesn’t seem to make any difference on the outcome of the compile).
  2. The JOGL project library doesn’t show up under the project folder, as it does when using the User Library
  3. To see the JOGL project listed for selection, the project has to be open. If it is closed, it will not appear in the Select the project dialog.

The missing gluegen source zip file

As stated above, v0.7 of the, is missing the gluegen java source zip file.

From this reply to issue 44, the missing gluegen source zip file ( is available here,,  however, I am unable to locate it.

It seems that v2.4 has hidden, or no longer includes, the gluegen source. Whereas for v2.3 the gluegen source is under archive/Sources. However, it may be that the gluegen source is now included in, which is under the fat directory, in v2.4.x. The gluegen source is then found in the expanded zip under com/jogamp/gluegen.

However, that leads to the question as to how one specifies the Source Attachment of the gluegen JAR file when creating the library as a User Library or Project.

Converting .7z to .zip

From this answer to Repack 7z files to zip files in linux



for x in `ls *.7z`; do
    mkdir $TMPDIR
    cd $TMPDIR
    cp ../$x .
    p7zip -d $x
    zip -r ../${x%.7z}.zip *
    cd ..
    rm -rf $TMPDIR    

or more simply, from this answer:

arepack -e -F zip *.7z

Related links

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s