Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Welcome to Pi4J

## Welcome to Pi4J

**Latest release: V3.0.3 (2025-09-23, see [Release Notes](/about/release-notes/)).**
**Latest release: V4.0.0 (2025-??-??, see [Release Notes](/about/release-notes/)).**

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**.

Expand All @@ -28,6 +28,8 @@ The Pi4j project has evolved in all these years as the whole Java eco-system and
* In 2.5.0, support for the Raspberry Pi 5 was added. Because of the new [GPIO chip RP1](https://www.raspberrypi.com/documentation/microcontrollers/rp1.html), a new GPIO Provider was needed. See the [this interview](/blog/2024/20240318_interview_alexander_liggesmeyer/).
* [V3.X.X](/about/info-v3): Based on Pi4J 2.8.0 and Java 21.
* Please [read this blog post for more info](/blog/2025/20250211-welcome-java-21/).
* [V4.X.X](/about/info-v4): Based on Pi4J 3.0.3 and Java 25.
* Please [read this interview with Nick Gritsenko (aka DigitalSmile) for more info](/blog/2025/2025????-interview-nick-ffm/).

### Project Mission/Goals

Expand Down
21 changes: 21 additions & 0 deletions content/about/info-v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: 'What''s New in V4'
weight: 23
tags: ["FFM API"]
---

Versions 4.0.0 is based on 3.0.3 (released on 2025-09-23), but bumps the **Java version to 25** and has a new plugin that uses the Foreign Function & Memory (FFM) API. See the [release notes](/about/release-notes/???).

## FFM Plugin

The goal of this bump to V4 is to enable the use of the Foreign Function & Memory (FFM) API in Pi4J. This FFM API has been introduced in OpenJDK 22 and simplifies the use of native libraries in Java. And native libraries are "the heart" of the Pi4J project as they provide the connection between your Java code and the hardware.

Thanks to the contributions by [Nick Gritsenko (aka DigitalSmile)](https://github.com/DigitalSmile) in [pull request #458](https://github.com/Pi4J/pi4j/pull/458), a complete new plugin got added to Pi4J. Read more about the work by Nick in this [interview](/blog/2025/2025????-interview-nick-ffm/).

## Sources

The Pi4J V4 source code is available in this GitHub repository: [`pi4j/pi4j` GitHub Repository](https://github.com/Pi4J/pi4j)

```shell
git clone https://github.com/Pi4J/pi4j
```
26 changes: 4 additions & 22 deletions content/about/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ weight: 40

All releases of Pi4J V2+ are listed on [github.com/Pi4J/pi4j/releases](https://github.com/Pi4J/pi4j/releases).

## V4

Requires Java 25, see [What's New in V4](/about/info-v4/) for more info.

## V3

Requires Java 21, see [What's New in V3](/about/info-v3/) for more info.
Expand Down Expand Up @@ -93,28 +97,6 @@ Special thanks to [Dariusz Zbyrad](https://github.com/dariuszzbyrad) for joining

All changes: https://github.com/Pi4J/pi4j/compare/2.7.0...2.8.0

### 2025-01-28 - V2.8.0

* Several code and JavaDoc improvements by adding the checkstyle plugin.
* Improvements in loading the Mock providers to build and test Pi4J on a Raspberry Pi.
* Issue [#421](https://github.com/Pi4J/pi4j/issues/421): Unable to detect board type. Several improvements have been integrated in the board detection to prevent errors when reading the board code.
* Added to `BoardModel`:
* Issue [#406](https://github.com/Pi4J/pi4j/issues/406): Old boards not auto detected. Missing codes have been added for Model 1 boards.
* The Raspberry Pi Compute 5. Only the board code `c04180` for the 4Gb has been confirmed by Jeff Geerling. The other types are not documented yet. We assume they are `a04180`, `b04180`, and `d04180`, similar to the Compute 4, but will adjust whenever more info is available.
* The Raspberry Pi 500 with the board code `d04190`, again confirmed by Jeff who received an evaluation device.
* The Raspberry Pi 5 with 16GB memory with the board code `e04171` (thanks again Jeff).
* Added to `BoardReading`:
* Pull request [#432](https://github.com/Pi4J/pi4j/pull/432): Add Support for Throttled State Parsing and Retrieval
* Improvements in the LinuxFS provider (for Raspberry Pi 5):
* Pull Request [#433](https://github.com/Pi4J/pi4j/pull/433): Enhance LinuxFsI2CBus validation with detailed exception messages and comprehensive Javadocs.
* Pull Request [#434](https://github.com/Pi4J/pi4j/pull/434): Add SPI support in LinuxFS. No `sudo` is needed to use SPI.

Thanks to contributions by [@mpilone](https://github.com/mpilone), [@cniesen](https://github.com/cniesen), [@geerlingguy](https://github.com/geerlingguy), [@dariuszzbyrad](https://github.com/dariuszzbyrad), [@taartspi](https://github.com/taartspi), [@eitch](https://github.com/eitch), [@fdelporte](https://github.com/fdelporte).

Special thanks to [Dariusz Zbyrad](https://github.com/dariuszzbyrad) for joining the project and improving the Maven builds with a wrapper for more consistency, for example, in the [pi4j-example-devices repository](https://github.com/Pi4J/pi4j-example-devices), and other contributions. And also special thanks to [Mike Pilone](https://github.com/mpilone) for the initial work for LinuxFS SPI.

All changes: https://github.com/Pi4J/pi4j/compare/2.7.0...2.8.0

### 2024-10-03 - V2.7.0

* Libraries are loaded depending on the platform, by calling `BoardInfoHelper.runningOnRaspberryPi()`.
Expand Down
102 changes: 102 additions & 0 deletions content/blog/2025/2025????-interview-nick-ffm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "Interview Nick Gritsenko"
date: 2025-01-15
tags: ["FFM API"]
---

2025-09-17 by Frank Delporte

## Pi4J Goes Beyond Raspberry Pi with Java 22's FFM API

*Nick Gritsenko (aka [DigitalSmile](https://www.linkedin.com/in/nick-gritsenko/)) joined the Pi4J project recently with an interesting plugin that uses Java 22's Foreign Function & Memory API. His work could open up Pi4J to run on a significantly wider range of hardware than just Raspberry Pi.*

---

### About Nick

**Frank:** Thanks for joining the Pi4J community! What's your background?

**Nick:** I work at Yandex in the infrastructure department. We're actually discussing moving from classic x86 AMD64 systems to ARM or even RISC-V in our data centers. The hardware landscape is changing fast, and I think RISC-V will make serious progress in the next 10 years.

**Frank:** What brought you to Pi4J?

**Nick:** I was already working on [an FFM API-based GPIO library for Raspberry Pi](https://github.com/DigitalSmile/gpio), and it seemed like a perfect fit to become a Pi4J plugin. The thing is, with FFM we can make Pi4J work on any hardware that runs Linux... Orange Pi, RISC-V system-on-chips, whatever. The FFM API basically lifts the hardware abstraction above the Linux ecosystem level.

### What is the FFM API

**Frank:** Can you explain what the FFM API is for readers who haven't heard of it?

**Nick:** The Foreign Function & Memory API is part of the [OpenJDK Project Panama](https://openjdk.org/projects/panama/), which actually started way back in 2014. The big difference between FFM and traditional approaches like JNI, JNA, or JNR is huge: **you don't need to know C or C++**. As Java developers, why should we have to become C++ experts just to talk to native code?

The traditional approaches have two main problems. First, writing production-ready C++ code requires deep expertise - you can't learn that from some "C++ in 21 days" book. Second, all those abstraction layers create serious runtime overhead with multiple layers the JVM has to handle.

**Frank:** How is FFM different?

**Nick:** With FFM, you stay in pure Java. Not a single line of C or C++ in your application. You describe C structures using Java, and FFM handles the conversion. Since it's pure Java bytecode, the JIT compiler can optimize it properly, so you can use it safely in, for example, high-load Spring applications.

### How it Works with Pi4J

**Frank:** How does this work in practice?

**Nick:** If you look, for example, at the [sources of the GPIO package structures](https://github.com/Pi4J/pi4j/tree/develop/plugins/pi4j-plugin-ffm/src/main/java/com/pi4j/plugin/ffm/common/gpio/structs) I've created, they're Java representations of the C structures that describe how GPIO functionality works in Linux. You're building the same model that represents the C world, but in Java terms.

When you want to change a digital output state, you're calling `ioctl` directly from Java to the kernel. FFM automatically handles converting between Java objects and the native C world.

**Frank:** What about performance?

**Nick:** I've done measurements comparing the FFM implementation with existing Pi4J approaches. The results are impressive, as the removal of all the steps inbetween with JNI and JNA shows a big difference between the "old" implementation and the FFM plugin. Removing the abstraction layers brings big performance improvements.

```text
Benchmark Mode Cnt Score Error Units
GPIOPerformanceTest.testFFMInputRoundTrip avgt 5 0.173 ± 0.003 ms/op
GPIOPerformanceTest.testGpioDInputRoundTrip avgt 5 10.537 ± 6.196 ms/op
GPIOPerformanceTest.testLinuxFsInputRoundTrip avgt 5 111.781 ± 42.199 ms/op

Benchmark Mode Cnt Score Error Units
GPIOPerformanceTest.testFFMInputWithListenerRoundTrip avgt 5 1.594 ± 5.830 ms/op
GPIOPerformanceTest.testGpioDInputWithListenerRoundTrip avgt 5 9.015 ± 12.139 ms/op
GPIOPerformanceTest.testLinuxFsInputWithListenerRoundTrip avgt 5 110.115 ± 18.796 ms/op

Benchmark Mode Cnt Score Error Units
GPIOPerformanceTest.testFFMOutputRoundTrip avgt 5 0.042 ± 0.001 ms/op
GPIOPerformanceTest.testGpioDOutputRoundTrip avgt 5 0.110 ± 0.002 ms/op
GPIOPerformanceTest.testLinuxFsOutputRoundTrip avgt 5 108.306 ± 12.490 ms/op
```

### Challenges

**Frank:** Any downsides to FFM?

**Nick:** The main issue is crash handling. If something in the native code throws an exception, your entire JVM crashes - not just your application. This isn't unique to FFM though. The potential solution would be sandboxing, where native crashes wouldn't kill the whole JVM, but I haven't seen concrete plans for that yet.

**Frank:** How do you handle different hardware requirements?

**Nick:** This is important - I'm strictly against putting any Raspberry Pi-specific code directly in the FFM implementation. Everything should go through plugins. Pi4J already has a plugin system for providers, but I think we should extend this to hardware-specific things... plugins for Raspberry Pi, Orange Pi, RISC-V chips, etc.

The beauty of FFM is that it works with any hardware running Linux. We're not abandoning Raspberry Pi, but we can expand to other platforms much easier.

### Future Vision

**Frank:** Where do you see this going?

**Nick:** This opens up completely new possibilities. At work, we're already seeing the industry move toward ARM and RISC-V because Java runs much more efficiently on ARM than x86. With FFM, Pi4J can be part of that future across all these platforms.

The goal is making Pi4J truly platform-agnostic while keeping the ease of use Java developers expect. No more dealing with native libraries, compilation issues, or platform-specific builds.

**Frank:** Advice for developers who want to contribute?

**Nick:** The FFM learning curve isn't as steep as you might think. Once you understand the byte mathematics and how to map structures between Java and native worlds, it becomes straightforward - though I won't say it's just "copy and paste"!

I'd say about 70-80% of my time was spent understanding how FFM works. Once that clicked in my brain, development speeded up significantly.

### Getting Involved

**Frank:** How can the community help?

**Nick:** Testing is crucial. I've been working with a Raspberry Pi 5, and basic functionality like digital outputs works well. But we need testing across all providers to identify corner cases that only show up in real-world usage. We also need feedback from developers trying different hardware platforms. The more diverse our testing, the more robust the implementation becomes.

---

*Nick's work integrating Java 22's FFM API represents a big step forward for Pi4J, potentially opening doors to a much broader ecosystem of single-board computers and IoT devices. Try it out and let us know how it works!*

*Want to learn more about Pi4J or contribute? Check out the [GitHub repository](https://github.com/Pi4J/pi4j) or visit the [Pi4J website](https://www.pi4j.com).*
6 changes: 6 additions & 0 deletions content/documentation/providers/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ expressly requested when creating the Context. [See Create Context](../create-c

Current supported providers:

* [FFM](/documentation/providers/ffm/)
* Was introduced in Pi4J 4.0.0
* Pro
* ...
* Contra
* ...
* [GpioD](/documentation/providers/gpiod/)
* Was introduced in Pi4J 2.5.0
* Pro
Expand Down
77 changes: 77 additions & 0 deletions content/documentation/providers/ffm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: FFM Provider
weight: 91
tags: ["FFM"]
---

The FFM plugin provider was added in Pi4J 4.0.0 based on the Foreign Function & Memory (FFM) API

Providers in the FFM plugin:

* ffm-digital-input
* ffm-digital-output
* ffm-i2c
* ffm-pwm
* ffm-serial
* ffm-spi

## Quick start

1. Ensure you are running JDK25+
2. Add `--enable-native-access=com.pi4j.plugin.ffm` to your run or add to MANIFEST.MF `Enable-Native-Access: ALL-UNNAMED`
3. Add dependency to your maven/gradle
``` xml
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-ffm-plugin</artifactId>
<version>${pi4j.version}</version>
</dependency>
```
4. (optional) Use new API Provided by package `...`

## Note on permissions

Since FFM provider does not rely on third-party native code and do all work between JVM and Linux kernel we have to be very cautious with permissions user have and devices setup correctly.
That is why we have a special checker, that helps users setup security aspect of using pi4j.

TLDR; Use `sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/,,,/permissions_install.sh)"` and reboot the device.

What the user should consider:
1. Do not run any of pi4j FFM with `sudo` or by `root`. That's unsecure and third-party dependencies added to your application can compromise you hardware.
2. Make sure you have right groups in your distro:
- Raspbian: `gpio` group and current user should be the member of this group
- Ubuntu: `dialout` group and current user should be the member of this group
3. Make sure you have correct `udev` rules, that are running your devices:
- All devices should belong to group `gpio` or `dialout`
- All devices should have `0660` rights to access them in safe manner


## Implementation notes

### GPIO (Digital Input / Digital Output)

### I2C

### SPI

### Serial

Serial protocol is considered as alpha for now, use at your own risk.

### PWM

## Supported Operating System Versions

Any Linux kernel with GLIBC >= 2.13. That covers all modern distros (Ubuntu, Raspbian, Debian, Arch, etc.).

## Dependencies

To use the FFM provider include the following dependencies:

``` xml
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-ffm-plugin</artifactId>
<version>${pi4j.version}</version>
</dependency>
```
2 changes: 1 addition & 1 deletion content/documentation/providers/gpiod.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: GpioD Provider
weight: 91
weight: 92
tags: ["GpioD", "Digital Input", "Digital Output"]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ tags: ["Visual Studio Code"]
Please check the [Prepare a Raspberry Pi](/prepare/install-java/) and [Install Java and Tools](/prepare/install-java/) instructions.
{{% /notice %}}

You need Java 21 or newer to use Pi4J V3+. On a board with ARMv7 or ARMv8 you will get this result:
You need Java 25 or newer to use Pi4J V4+. On a board with ARMv7 or ARMv8 you will get this result:

```shell
$ java -version
openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Zulu21.38+21-CA (build 21.0.5+11-LTS, mixed mode, sharing)
openjdk version "25" 2025-09-16 LTS
OpenJDK Runtime Environment Zulu25.28+85-CA (build 25+36-LTS)
OpenJDK 64-Bit Server VM Zulu25.28+85-CA (build 25+36-LTS, mixed mode, sharing)
```

Keep in mind this version is **only compatible with ARMv7 or higher** and doesn't support all
Expand Down