Pi4J, the Java library to control the GPIOs of the Raspberry Pi
  • Java 93.6%
  • HTML 2.6%
  • C 2.3%
  • Shell 1.2%
  • Python 0.3%
Find a file
Robert von Burg 5cc5d894e2
Some checks failed
CodeQL analysis / Analyze (actions) (push) Failing after 3s
CodeQL analysis / Analyze (java-kotlin) (push) Failing after 1s
Build snapshot and deploy to Maven / Build & Deploy Snapshot (push) Failing after 1s
Build snapshot and deploy to Maven / Deploy to Download Repo (push) Has been skipped
Merge pull request #701 from Pi4J/pwm-refactroing-v1
PWM refactoring and optimizations
2026-07-21 10:05:03 +02:00
.codegraph Added fixes to RISC-V architecture, some minor fixes to run JMH benchmarks 2026-07-17 17:08:05 +03:00
.github/workflows Potential fix for pull request finding 2026-07-06 08:33:31 +02:00
.mvn/wrapper build: Pi4J#562 Update Maven version from 4.0.0-rc-4 to 4.0.0-rc-5 (pi4j docker image maven version) 2026-07-02 04:58:57 +01:00
.run [Project] Enabling building of gpiod plugin 2024-01-22 16:11:47 +01:00
assets/draw.io Update README 2026-06-15 11:21:11 +02:00
config/checkstyle Readd default rules 2024-11-16 15:46:16 +01:00
jmh-results #643 Added JMH tests 2026-06-13 10:14:56 +03:00
pi4j-core Reverted reconfigure option for GPIO 2026-07-21 08:16:41 +03:00
pi4j-test call super.initialize(context) in PwmBase 2026-07-14 18:43:54 +01:00
plugins Merge pull request #701 from Pi4J/pwm-refactroing-v1 2026-07-21 10:05:03 +02:00
.editorconfig added initial editor config for code style + README additions 2020-05-29 23:55:49 +02:00
.gitattributes Add fzz binary to avoid corrupting Fritzing wiring files 2026-02-20 09:08:08 +01:00
.gitignore Ignore test trace logs 2026-02-05 13:37:03 +01:00
autoRelease [Fix] Fixed deployment missing artifacts 2024-03-21 09:45:35 +01:00
autoReleaseBranch [Fix] Fixed deployment missing artifacts 2024-03-21 09:45:35 +01:00
CLA.md Commonhaus docs 2026-06-22 16:35:09 +02:00
CODE_OF_CONDUCT.md Commonhaus docs 2026-06-22 16:35:09 +02:00
CONTRIBUTING.md Commonhaus docs 2026-06-22 16:38:18 +02:00
dco.txt Commonhaus docs 2026-06-22 16:35:09 +02:00
deployToMavenCentral.sh [Project] Don't call package when deploying 2025-03-24 07:46:02 +01:00
GOVERNANCE.md Commonhaus docs 2026-06-22 16:35:09 +02:00
jreleaser.yml Potential fix for pull request finding 2026-07-06 08:31:24 +02:00
LICENSE.txt iniital commit 2019-06-18 14:18:05 -04:00
mvnw build: Pi4J#562 Update Maven version from 3.9.4 to 4.0.0-rc-4 and wrapper version 3.3.2 to 3.3.4 2026-07-02 04:58:56 +01:00
mvnw.cmd build: Pi4J#562 Update Maven version from 3.9.4 to 4.0.0-rc-4 and wrapper version 3.3.2 to 3.3.4 2026-07-02 04:58:56 +01:00
NOTICE.txt Avoid yearly code changes by removing years from the classes 2021-03-02 09:55:19 +01:00
pom.xml build: Issue Pi4J#562 PR Pi4J#612 fix build failure by upgrading maven compiler plugin from 3.13.0 to 3.15.0 2026-07-02 04:58:57 +01:00
README.md Update README 2026-06-15 12:01:58 +02:00
RELEASE.md Automate release flow from main with jreleaser, similar to pi4j-drivers, aligning with Commonhaus release requirements. 2026-07-06 08:24:32 +02:00
SECURITY.md Commonhaus docs 2026-06-22 16:35:09 +02:00
udev.rules Workflow changes requested by @DigitalSmile in https://github.com/Pi4J/pi4j/pull/615#issuecomment-3957268972 2026-02-25 08:39:06 +01:00

Pi4J :: Java I/O Library for Raspberry Pi

Maven Central Snapshot License

Site Chat on Slack Pi4J on Mastodon Pi4J on LinkedIn

API documentation: APIdia


Project Information

Project website: pi4j.com.

This project is intended to provide a friendly object-oriented I/O API and implementation libraries for Java Programmers to access the full I/O capabilities of the Raspberry Pi platform. This project abstracts the low-level native integration and interrupt monitoring to enable Java programmers to focus on implementing their application business logic.

Pi4J diagram

Builds are available from:

Using Pi4J

You need these Java 25+ runtimes to use Pi4J (V4+):

When you want to use Pi4J in your project, you should definitely check out the Pi4J website where you can find a lot of information and many examples!

For example, for a minimal example to blink a LED (fully explained here), you need to import the dependencies and use this code:

var pi4j = Pi4J.newAutoContext();

var led = pi4j.digitalOutput().create(PIN_LED);

while (true) {
  if (led.state() == DigitalState.HIGH) {
    led.low();
  } else {
    led.high();
  }

  Thread.sleep(500);
}

Contributing to Pi4J

For full description of the code structure, how to compile... see the "About the code" on our website.

Pi4J code structure

Project Overview

Starting with Pi4J V2, the Pi4J project is prioritizing focus on providing Java programs access, control and communication with the core I/O capabilities of the Raspberry Pi platform. A separate repository pi4j-drivers provides drivers for various electronic components, using the Pi4J library.

Read all about it on pi4j.com: What's New in V2, in V3, and in V4.

Build Instructions

The Pi4J codebase can be built using Apache Maven and Java JDK 25 (since V4). The following command can be used to build the Pi4J JARs:

mvn package

With package all modules in the Pi4J project will be built, and it shows you if the project can be successfully built. If you want to use the libraries locally on your Raspberry Pi, for example, for testing, replace package with install.

NOTE: A comprehensive set of build instructions can be found in the Pi4J Documentation.

Adding a feature or solving a problem

If you have an idea to extend and improve Pi4J, please first create a ticket to discuss how it fits in the project and how it can be implemented.

If you find a bug, create a ticket, so we are aware of it and others with the same problem can contribute what they already investigated. And the quickest way to get a fix? Try to search for the cause of the problem or even better provide a code fix!

Join the team

You want to become a member of the Pi4J-team? Great idea! Send a short message to frank@pi4j.com with your experience, ideas, and what you would like to contribute to the project.

License

Pi4J Version 2.0 and later is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (C) 2012 - 2026 Pi4J