Tag Archives: GPIO

More Raspberry Pi Awesomeness: GPIO & Java

I’ve been playing with the GPIO capabilities of the Raspberry Pi before using Python, which comes with easy GPIO access for the Raspberry Pi.

Java 8 for ARM

As I’m yet not very familiar with Python I got excited when Oracle accounced Java 8 for the ARM platform, so I downloaded the JDK 8 (with JavaFX) for ARM Early Access from the Oracle website, copied it to the RPi, compiled an example app on my PC and copied the JAR to the RPi – and it runs!

Obviously it takes some time to start the application but it works as excepted; of course it was a very simple example and there are some limitations, especially when it comes to graphics output, but it’s a good start.

There is even JavaFX support in the JDK 8 which will output to RPi’s HDMI/Video output, but that’s a topic for another posting ;)

Java & GPIO

There is no native support for the RPi’s GPIO pins in Java, but there are two Open Source projects to get it running anyway:

  • WiringPi – an easy-to-use C library to control the GPIO pins
  • Pi4j – a Java class library providing a bridge between native code and Java to access the GPIO pins

As described on the WiringPi website you can get WiringPi via git, and then build it directly on the RPi.

The Pi4j website has lots of examples on how to work with the code, and from a Java developer’s perspective it is pretty straight forward to use Pi4j.

I’ve used some code directly from the Pi4j’s example pages, put an LED on a breadboard, connected two pins and when running the program the LED blinks! Great!

So, if you are planing to access GPIO via Java you should definitely take a look at WiringPi and Pi4j.