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
Prepare your Raspberry Pi (Running Arch linux):
sudo pacman -S git-core make gcc libtool jdk7-openjdk
Install WiringPi on your Raspberry Pi:
git clone git://git.drogon.net/wiringPi cd wiringPi ./build
Test the WiringPi install:
gpio -v gpio readall
Set JAVA_HOME on your default profile:
sudo vim /etc/profile export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
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
Clone the Github Pi4j Arch project:
git clone https://github.com/glnds/pi4j-arch
Adjust the pom.xml
cd pi4j-arch vim pom.xml ... <!-- DEFAULT RASPBERRY PI PROPERTIES --> <pi.host>192.168.1.1</pi.host> <pi.port>22</pi.port> <pi.user>root</pi.user> <pi.password>root</pi.password> ...
Install Maven: http://maven.apache.org/
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
...
user ALL=(ALL) NOPASSWD: ALL
...
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
- If not yet downloaded, download the Arch build here (or use your own build).
Copy the Pi4J library to your Raspberry pi:
scp pi4j-0.0.5.tar.gz pi@rpi.local:~/
Extract the archive:
tar -xvzf pi4j-0.0.5.tar.gz
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