Pi4J for Arch Linux

Some time ago I used Pi4J in one of my Raspberry Pi projects running Raspian. While trying to migrate this project to Arch Linux recently, I was unable to find a Pi4J version for that distribution. In the end I got it running by making a Pi4J version for Arch Linux myself. This tutorial describes how to build Pi4J on Arch.

If you don’t want to build the library yourself, you can just download the build here.

The installation instructions are at the bottom of this article and in the README on Github.

How to build Pi4J on Arch Linux

  1. Prepare your Raspberry Pi (Running Arch linux):

    sudo pacman -S git-core make gcc libtool jdk7-openjdk
  2. Install WiringPi on your Raspberry Pi:

    git clone git://git.drogon.net/wiringPi
    cd wiringPi
  3. Test the WiringPi install:

    gpio -v
    gpio readall
  4. Set JAVA_HOME on your default profile:

    sudo vim /etc/profile
    export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
  5. Set JAVA_HOME for your default environment. This is needed when Maven will connect with the Raspberry Pi over SSH.

    sudo vim  /etc/environment
    export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
  6. Clone the Github Pi4j Arch project:

    git clone https://github.com/glnds/pi4j-arch
  7. Adjust the pom.xml

    cd pi4j-arch
    vim pom.xml
  8. Install Maven: http://maven.apache.org/

  9. Build Pi4J:

    mvn clean install -P native -P hard-float

Important note: currently, the script only works when executed by the root user. If you want to run it under a different user, you will have to grant the user root privileges and suppress its need to provide a password. I’ve not tested it but probable you have to setup your user like this:

sudo visudo

You will also have to do some minor adjustments to the build.xml file.

This build procedure is based on the original build instruction of Pi4J.

Install Pi4j on Arch Linux

  1. If not yet downloaded, download the Arch build here (or use your own build).
  2. Copy the Pi4J library to your Raspberry pi:

    scp pi4j-0.0.5.tar.gz pi@rpi.local:~/
  3. Extract the archive:

    tar -xvzf pi4j-0.0.5.tar.gz
  4. Install the libraries:

    sudo mkdir /opt/pi4j
    sudo mv ~/pi4j-0.0.5/lib/ /opt/pi4j/
    sudo mv ~/pi4j-0.0.5/examples/ /opt/pi4j/

Done! You can now use Pi4J on your Raspberry Pi running Arch Linux. Here’s an example:

sudo java -cp SomeJar.jar:.:classes:/opt/pi4j/lib/'*' be.pixxis.Example