B4J Question Raspberry Pi 4B jPi4J can't use

tzfpg

Active Member
Licensed User
Longtime User
I already update jPi4J to version 2.00 and I also follow the step in https://www.b4x.com/android/forum/threads/raspberry-pi-4b-gpio-not-working.118488/#post-741684

my B4J version is 9.30 and use opendjk11

B4X:
pi@raspberrypi:~ $ gpio -v
gpio version: 2.52
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 4B, Revision: 02, Memory: 4096MB, Maker: Sony
  * Device tree is enabled.
  *--> Raspberry Pi 4 Model B Rev 1.2
  * This Raspberry Pi supports user-level GPIO access.

I have enable spi
B4X:
pi@raspberrypi:~ $ lsmod | grep spi
spidev                 20480  0
spi_bcm2835            24576  0

I create a small test project
B4X:
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private controller As GpioController
    Private p As GpioPinDigitalOutput
End Sub

Sub AppStart (Args() As String)
    Log("test")
    controller.Initialize
    p.Initialize(15, False)
    test
    StartMessageLoop
End Sub

Sub test
    Dim b As Boolean
    Do While True
        p.State = b
        b = Not(b)
        Log(b)
        Sleep(1000)
    Loop
End Sub

But still can't make it work
B4X:
Waiting for debugger to connect...
Program started.
test
Unable to determine hardware version. I see: Hardware    : BCM2711
,
 - expecting BCM2708, BCM2709 or BCM2835.
If this is a genuine Raspberry Pi then please report this
to projects@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY.

I really need to know how to make it work.

Thank you.
 

tzfpg

Active Member
Licensed User
Longtime User
Now waiting new update for library and any temporary solution or alternative way to solve this problem?
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
I'm start to test the Pi4j2 library, but I'm still getting error show up.

Error:
Waiting for debugger to connect...
Program started.
Hello world!!!
Dec 22, 2021 10:04:08 AM com.pi4j.Pi4J newAutoContext
INFO: New auto context
Dec 22, 2021 10:04:08 AM com.pi4j.Pi4J newContextBuilder
INFO: New context builder
Dec 22, 2021 10:04:09 AM com.pi4j.platform.impl.DefaultRuntimePlatforms add
INFO: adding platform to managed platform map [id=raspberrypi; name=RaspberryPi Platform; priority=5; class=com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform]
Dec 22, 2021 10:04:09 AM com.pi4j.library.pigpio.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j-pigpio.so] using path: [/lib/armhf/libpi4j-pigpio.so]
java.lang.UnsatisfiedLinkError: /tmp/libpi4j-pigpio10003958980443074313.so: libpigpio.so.1: cannot open shared object file: No such file or directory
    at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
    at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
    at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
    at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2627)
    at java.base/java.lang.Runtime.load0(Runtime.java:768)
    at java.base/java.lang.System.load(System.java:1837)
    at com.pi4j.library.pigpio.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:221)
    at com.pi4j.library.pigpio.util.NativeLibraryLoader.load(NativeLibraryLoader.java:162)
    at com.pi4j.library.pigpi
o.internal.PIGPIO.<clinit>(PIGPIO.java:74)
    at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioInitialise(PiGpioNativeImpl.java:91)
    at com.pi4j.library.pigpio.PiGpio.initialize(PiGpio.java:146)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:60)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:41)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:100)
    at com.sun.proxy.$Proxy2.create(Unknown Source)
    at com.pi4j.context.Context.create(Context.java:317)
    at com.pi4j.internal.IO
Creator.create(IOCreator.java:58)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
    at anywheresoftware.b4j.objects.Pi4JWrapper$DigitalOutputWrapper.Initialize(Pi4JWrapper.java:79)
    at b4j.example.main$ResumableSub_Start.resume(main.java:102)
    at b4j.example.main._start(main.java:77)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.Na
tiveMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.main(main.java:29)
Error occurred on line: 20 (Main)
java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy2.create(Unknown Source)
    at com.pi4j.context.Context.create(Context.java:317)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:58)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
    at anywheresoftware.b4j.objects.Pi4JWrapper$DigitalOutputWrapper.Initialize(Pi4JWrapper.java:79)
    at b4j.example.main$ResumableSub_Start.resume(main.java:102)
    at b4j.example.main._start(main.java:77)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywhe
resoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.main(main.java:29)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.j
ava:566)
    at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:100)
    ... 23 more
Caused by: java.lang.UnsatisfiedLinkError: Pi4J was unable to extract and load the native library [/lib/armhf/libpi4j-pigpio.so] from the embedded resources inside this JAR [/home/pi/debug/tempjars/AsyncInput1]. to a temporary location on this system.  You can alternatively define the 'pi4j.library.path' system property to override this behavior and specify the library path.
    at com.pi4j.library.pigpio.util.NativeLibraryLoader.load(NativeLibraryLoader.java:170)
    at com.pi4j.library.pigpio.internal.PIGPIO.<clinit>(PIGPIO.java:74)
    at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioInitialise(PiGpioNativeImpl.java:91)
    at com.pi4j.library.pigpio.PiGpio.initialize(PiGpio.java:146)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:60)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigi
talOutputProviderImpl.java:41)
    ... 28 more

My Raspberry Pi 4 OS
B4X:
Raspberry Pi OS Lite
Release date: October 30th 2021
Kernel version: 5.10
Size: 463MB
Show SHA256 file integrity hash:
Release notes

java version is JDK11 and I use sudo to run b4j-bridge.jar
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
After I delete Pi4j V1 old vervsion, another error message come out
B4X:
Waiting for debugger to connect...
Program started.
Hello world!!!
Dec 22, 2021 11:01:41 AM com.pi4j.Pi4J newAutoContext
INFO: New auto context
Dec 22, 2021 11:01:41 AM com.pi4j.Pi4J newContextBuilder
INFO: New context builder
Dec 22, 2021 11:01:41 AM com.pi4j.platform.impl.DefaultRuntimePlatforms add
INFO: adding platform to managed platform map [id=raspberrypi; name=RaspberryPi Platform; priority=5; class=com.pi4j.plugin.raspberrypi.platform.RaspberryPiPlatform]
Error occurred on line: 20 (Main)
java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy7.create(Unknown Source)
    at com.pi4j.context.Context.create(Context.java:317)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:58)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
    at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
    at anywheresoftware.b4j.objects.Pi4JWrapper$DigitalOutputWrapper.Initialize(Pi4JWrapper.java:79)
    at b4j.example.main$ResumableSub_Start.resume(main.java:102)
    at b4j.example.main._start(main.java:77)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.main(main.java:29)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:100)
    ... 23 more
Caused by: java.lang.ExceptionInInitializerError
    at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioInitialise(PiGpioNativeImpl.java:91)
    at com.pi4j.library.pigpio.PiGpio.initialize(PiGpio.java:146)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:60)
    at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:41)
    ... 28 more
Caused by: java.lang.IllegalStateException: Pi4J has detected and UNKNOWN/UNSUPPORTED 'os.arch' : [amd64]; only 'arm|armhf' and 'arm64|aarch64' are supported.
    at com.pi4j.library.pigpio.util.NativeLibraryLoader.load(NativeLibraryLoader.java:154)
    at com.pi4j.library.pigpio.internal.PIGPIO.<clinit>(PIGPIO.java:74)
    ... 32 more
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
Are you sure that you are running it on the Pi and not on the PC? How is the arch amd64?
Make sure that the bridge is connected.
I'm using Raspberry pi 4 and I connected to bridge.
Sorry that amd64 is I'm not yet connect to bridge.
 
Last edited:
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
I had try release and run on raspberry pi 4 and get this error message
B4X:
main._appstart (java line: 494)
java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy4.create(Unknown Source)
        at com.pi4j.context.Context.create(Context.java:317)
        at com.pi4j.internal.IOCreator.create(IOCreator.java:58)
        at com.pi4j.internal.IOCreator.create(IOCreator.java:96)
        at com.pi4j.internal.IOCreator.create(IOCreator.java:176)
        at anywheresoftware.b4j.objects.Pi4JWrapper$DigitalOutputWrapper.Initialize(Pi4JWrapper.java:79)
        at b4j.example.main._appstart(main.java:494)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
        at b4j.example.main.main(main.java:31)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:100)
        ... 14 more
Caused by: java.lang.UnsatisfiedLinkError: Pi4J was unable to extract and load the native library [/lib/armhf/libpi4j-pigpio.so] from the embedded resources inside this JAR [/home/pi/swp/rpi_server/rpi_bast.jar]. to a temporary location on this system.  You can alternatively define the 'pi4j.library.path' system property to override this behavior and specify the library path.
        at com.pi4j.library.pigpio.util.NativeLibraryLoader.load(NativeLibraryLoader.java:170)
        at com.pi4j.library.pigpio.internal.PIGPIO.<clinit>(PIGPIO.java:74)
        at com.pi4j.library.pigpio.impl.PiGpioNativeImpl.gpioInitialise(PiGpioNativeImpl.java:91)
        at com.pi4j.library.pigpio.PiGpio.initialize(PiGpio.java:146)
        at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:60)
        at com.pi4j.plugin.pigpio.provider.gpio.digital.PiGpioDigitalOutputProviderImpl.create(PiGpioDigitalOutputProviderImpl.java:41)
        ... 19 more
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
How come there is a different error message each time?

Are you running the bridge with sudo?
Thanks reply my message and thanks for gpa help me find out the problem, I didn't install the pigpio package, after install the package, all run perfect!
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Thanks reply my message and thanks for gpa help me find out the problem, I didn't install the pigpio package, after install the package, all run perfect!
Why do you need to install pigpio?
 
Upvote 0
Top