Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 448 forks source link

Using Pi4J 1.2 Java Library with Raspberry 4 - Sharing Docker file to produce : libpi4j.so #510

Closed fguiet closed 3 years ago

fguiet commented 3 years ago

Update : Oops => just realized that a new version Pi4J v2 was on going https://v2.pi4j.com/....well maybe it will help some of you to use last official release of Pi4J 1.2 with Raspberry Pi 4 and WiringPi :) As for me, now I wait eagerly for an official V2 release ... but git repo seems to be really quiet...

Hi,

You want to use Pi4J 1.2 Java Library with Raspberry 4 and arm64 architecture?

You know that last version of Pi4J (1.2 as of 2020/12/05) contains the JNI library called libpi4j.so build for armhf architecture...So I would like to share this Dockerfile : https://github.com/fguiet/automationserver-v2/blob/main/libpi4j/builder/Dockerfile

Just run :

docker build -t libpi4j . docker run -it --rm -v /tmp:/tmp libpi4j /bin/bash -c "cp -r /applications/builder/output/libpi4j.so /tmp"

You'll get the libpi4j.so in your /tmp folder...built again last version of WiringPi (Raspberry 4 ready). All you have to do to use the Pi4J Java library is to replace lib\raspberrypi\dynamic\libpi4j.so in the Pi4J 1.2 Jar file that you can get from Maven Repository (or you can specify the location of the new compiled library via pi4j.library.path environment See : https://v2.pi4j.com/documentation/advanced/library-path I did not try this on v1.2 so dunno if it is working...)

You can build the WiringPi on your distro by running :

cd automationserver-v2/libpi4j/builder/vendor/WiringPi/master-20201205 && chmod u+x build && ./build

Now you can use the Pi4J 1.2 Jar file in your raspberry 4 java project to control GPIO :)

Use it at your own risk :)

I just tested on GPIO 2 (PJ4J numbering scheme) on a debian 10 distro with OpenJDK 11 installed ... so far so good !

My two cent, Fred

savageautomate commented 3 years ago

Thank you for sharing this effort.

Please be aware that Pi4J v1.3 was recently released (JDK8 & armhf only) and Pi4J v1.4 currently in development does already support a Docker build where you can build the entire project in a Docker container (Java JARs and Native Library) or just the libpi4j.so native shared library project. It does support both armhf and arm64 architectures and runs on newer JVMs. Our Docker containers (https://github.com/Pi4J/pi4j-docker) will use ARM cross-compilers so you can build on a traditional x64 platform or on an arm64 platform.

Thanks, Robert