B4J Library Pi4J2 - Raspberry Pi I/O library

At some point during 2019, the author of wiringpi, which is the native library that Pi4J was based on, stopped its development.

Luckily, there is a new version of Pi4J which is now being actively developed and it works with all recent versions of Raspberry Pi. It is not backward compatible.

jPi4J2 wraps the new Pi4J2 library. Currently only DigitalInput and DigitalOutput types are exposed. More to come...

Blink example:
B4X:
Sub Process_Globals
    Private pi4j As Pi4J
    Private PinOut As DigitalOutput
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Start
    StartMessageLoop
End Sub

Private Sub Start
    pi4j.Initialize("pi4j")
    PinOut.Initialize(pi4j, 2) 'BCM addresses: https://pi4j.com/documentation/pin-numbering/
    Do While True
        PinOut.State = Not(PinOut.State)
        Sleep(1000)
    Loop
End Sub

Input example:
B4X:
Sub Process_Globals
    Private pi4j As Pi4J
    Private PinIn As DigitalInput
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Start
    StartMessageLoop
End Sub

Private Sub Start
    pi4j.Initialize("pi4j")
    PinIn.Initialize(pi4j, "PinIn", 2, "PULL_DOWN", 3000)
End Sub

Private Sub PinIn_StateChange (State As Boolean)
    Log("New state: " & State)
End Sub

Note that it requires Java 11+.
You can install it with:
B4X:
sudo apt install default-jdk
And it is recommended to use B4J-Bridge:
B4X:
wget www.b4x.com/b4j/files/b4j-bridge.jar
sudo java -jar b4j-bridge.jar
 

Attachments

  • jPi4J2.zip
    5.6 KB · Views: 166
  • jPi4J2-dependencies.zip
    478.5 KB · Views: 159

jinyistudio

Well-Known Member
Licensed User
Longtime User

jinyistudio

Well-Known Member
Licensed User
Longtime User
Can i access jar of the jpi4j2 to access i2c,spi directly ?o_O
 
Top