Java:Reading data from a serial port.

Thisum
Thisum
Sep 1, 2018 · 2 min read

I’m working on a project, which includes IMUs to get data of hand gestures, and an Arduino to process the data - calculate: Yaw, Pitch andRoll. I’m using 6 IMUs, 5 for five fingers of the hand and the other one on the back of the hand. I’m using MPU9250 which has 9 DoF (3 axis accelerometer, 3 axis gyroscope and 3 axis magnetometer). Initially I was using Arduino Mini, but then started using Teensy 3.6 as It’s more powerful and faster than Arduino and can also work with Arduino framework.

Project involves:

  • creating a circuit to sense data
  • create a GUI to visualize data
  • classify the data according to gestures

To accomplish both visualisation and classification, I created a Java application. The major problem I had was setting up the environment to read from a serial port. RXTX is the most popular java library to read from a serial port. Although in the RXTX official page, the library installation procedure is described, for me it didn’t work (mac os — 10.12, java 8). I kept getting error messages during the run time about UnsatisfiedLinkError.

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver

This error was caused because, although I’ve added the RXTXcomm.jar file, librxtxSerial.jnilib file was missing.

But again, even after I added the jnilib file, I was getting an error saying: no suitable image found. The reason behind this is, jnilib file I used is an old one, and incompatible with the Java 8 system.

Then I found this page: http://jlog.org/rxtx-mac.html, which has the .jar file and the corresponding .jnilib file. After adding them to the /Library/Java/Extensions folder, my serial port reading code is working!!!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade