JInput on RaspberryPi

1.6k Views Asked by At

I am trying to get JInput working on a raspeberryPi. I know it is not ideal to use JInput without an ide, but the Raspberry Pi is too slow to work with most of them. I have managed to sucessfully compile and run my program from the command line on windows. However, on the pi i am having trouble. The pi is running raspbian, java version 1.7.0_40 with hotspot client vm build 24.0-b56. I have set up the file structure as so:

lib/dist
-jinput-test.jar
-jinput.jar
-Controller
--.dll, .so files
--LinuxEnvironmentPlugin.java
bin
src

I am using the command

java -Djava.library.path=lib/dist/Controller -Djinput.plugins=net.java.games.input.LinuxEnvironmentPlugin -cp bin:lib/dist/jinput.jar:lib/dist/Controller Main

to try and run.

However, i get

"INFO: Failed to load library:" /libjinput-linux64.so: /libjinput-linux64.so: wrong ELF class: ELFCLASSS64"

This is where I am confused. Why is it trying to use the 64 bit file. The rasperry Pi has a ARM version 6 processor, which only works with 32 bit. So why is it looking for the 64 bit file in the first place? I have also tried running with the -d32 option but that doesn't help.

4

There are 4 best solutions below

1
On

You need a native shared library (JNI) built for the Pi (ARM). Fortunately, there are pre-built raspbian packages for JInput that include the required native library:

  • sudo apt-get install libjinput-java libjinput-java-doc libjinput-jni

You should also add uinput to the end of /etc/modules so the controller gets detected. If you want a nice GUI to test the controller try also installing:

  • sudo apt-get install jstest-gtk
1
On

this puts the jar files in /usr/share/java/ which needs to be added to the CLASSPATH. I am still looking for the .so files which need to be added to the LD_LIBRARY_PATH

0
On

• Implemented a workaround.
• Wanted to implement joystick jogging on my Raspberry Pi, Processing3 GUI on a Grbl CNC machine, but hit the JInput <==> ARM incompatibility. Believe Quark is right in asserting that no ARM compatible JInput exists. This is in contradiction to the StackOverFlow thread JInput on RaspberryPi . Tried Albert’s extended apt-get: but no-joy Tried 2021-05-07-raspios-buster-arm64 from https://qengineering.eu/install-raspberry-64-os.html, but processing would not start. Went back to 32bit raspbian.
• Workaround was to add a second Arduino Uno with a USB host shield and run the Logetech 3D Pro joystick off the shield. Modified the Arduino USB Host Shield Library 2.0 le3dp sketch to have all output include an identifying preamble (J0Y) which allows the processing serialEvent to identify which USB port belongs to the Grbl Arduino and which is the joystick Arduino. Working code is at https://github.com/TPMoyer/Grbl4P and https://github.com/TPMoyer/LE3DP_4_Grbl4P

1
On

you can instal Jinput by

  • sudo apt-get install libjinput-java libjinput-java-doc libjinput-jni

then find these file on your raspberry pi after installation

  • jinput-20100502.jar
  • jinput.jar
  • jinput-test.jar
  • libjinput-linux.so
  • libjinput.so

make a new directory called (let's say) lib in your working directory (a you can name it as you wish) copy all the files above to the directory lib you just made. then compile the java file by this way :

  • sudo javac -cp "/usr/share/java/jinput.jar" Example.java

then run it by this way :

  • sudo java -Djava.library.path=./lib -cp ./lib/*:. Example

if you make the Example.java from netbeans, remove the package info line at the top. it should work.