Pi4J v1.x Documentation

repository·master·Indexed 23 days ago

https://github.com/pi4j/pi4j-v1

A Java I/O library providing Java programs with access, control, and communication capabilities for the core I/O features of the Raspberry Pi platform. Note that Pi4J Version 1.x is deprecated and archived; users are encouraged to migrate to Pi4J V2.0 for new projects. This documentation covers installation requirements, including OpenJDK 11 and unofficial WiringPi, as well as build instructions using Maven and Docker for Java and native libraries.

Tokens
982
Snippets
4
Records
10
Agent score
30%

What's inside Pi4J v1.x

  1. Migrate to Pi4J V2.0 for new projects

    master

    Pi4J Version 1.x is DEPRECATED and the repository is archived. For newer JDKs and Raspberry Pi models, you should use Pi4J V2.0.

    If you are starting a new project, it is highly recommended to migrate to the Pi4J Version 2.x codebase instead of using 1.x, which is only maintained for major bug fixes.

  2. Build Pi4J using Docker

    master

    If you want to build the entire Pi4J project without manually installing the JDK, Maven, or ARM cross-compilers, you can use the Pi4J builder Docker container. This container provides a consistent environment for all build steps. Ensure Docker is installed and running locally, then execute the commands from the root of the project directory.

    docker pull pi4j/pi4j-builder:1.4
    docker run --user "$(id -u):$(id -g)" --rm --volume $(pwd):/build pi4j/pi4j-builder:1.4
  3. Build the entire Pi4J project (Java and Native)

    master

    To build both the Pi4J Java libraries (JARs) and the native libraries (libpi4j.so), use the native profile along with either the docker or cross-compile profile.

    Building native libraries requires a cross-compiler environment. It is recommended to use the docker profile, which uses Docker containers to handle the native builds for 32-bit (libpi4j-armhf.so) and 64-bit (libpi4j-aarch64.so) ARM architectures, simplifying the process.

  4. Install the unofficial WiringPi for Raspberry Pi 4B and newer

    master

    The original WiringPi library is deprecated. To support Raspberry Pi 4B and newer systems, you must install the latest unofficial version maintained at https://github.com/WiringPi/WiringPi. As of 2021-01-12, this is version 2.60.

    sudo apt-get remove wiringpi -y
    sudo apt-get --yes install git-core gcc make
    cd ~
    git clone https://github.com/WiringPi/WiringPi --branch master --single-branch wiringpi
    cd ~/wiringpi
    sudo ./build
  5. Build Pi4J using Maven

    master

    You can compile Pi4J locally using Apache Maven.

    Prerequisites

    • Java 11: Any OpenJDK 11.0.7 or newer distribution. Note: The latest Oracle JDK 11 may fail to compile the project.
    • JAVA_HOME: Must be defined in your system environment.
    • Apache Maven: Version 3.6.x or newer.
    • ARM Cross-Compiler Toolchains: Required if you are not using the docker profile to build native libraries (ARMHF & AARCH64).
  6. Install OpenJDK 11 for Pi4J v1.x

    master

    Pi4J v1.x requires Java 11 (JDK) to build. Note that it may fail to compile with certain Oracle JDK distributions (e.g., 11.0.06, 11.0.07, 11.0.09, 11.0.10). It is recommended to use OpenJDK, Liberica, Zulu, or AdoptOpenJDK distributions.

    sudo apt-get install openjdk-11-jdk
  7. Build only Pi4J Java libraries

    master

    To build only the Pi4J Java libraries (JARs), run a standard Maven install. This command will not build native libraries; instead, it will use locally cached native libraries or download pre-compiled copies from the Maven repository.

    mvn clean install
  8. Reference: Pi4J Maven Native Build Profiles

    master

    When building native libraries, you must specify which environment to use via Maven profiles:

    ProfileDescription
    nativeInstructs Maven to build the native libraries
    dockerInstructs Maven to use a Docker container to build native libraries
    cross-compileInstructs Maven to use local cross-compiler toolchains to build native libraries