B4J Library [IoT] jPi4J - Raspberry Pi GPIO controller

Mark Turney

Active Member
Licensed User
Just received my RPI kit in the mail yesterday. Looking forward to using this library and B4J for some cool projects. I actually wound up ordering the Sunfounder kit too, as it added a number of components not included in the Canakit Ultimate. Specifically an ADC, lots of sensors, servo, ultrasonic sensor, another breadboard and more wires. It is the old style GPIO adapter and cable (26 pin), but that's not an issue as the Canakit includes the 40 pin model designed for the newer RPI.
 

alexhi

Member
Licensed User
Seems like the Pi4J library doesn't recognize this device as it is not a stock Raspberry Pi.
Hi
I try in console OrangePI PC:
echo 1 > /sys/class/gpio_sw/PA10/data and its work (LED switch ON)

and I try in b4j

shl.Initialize("shl","echo",Array As String( "1 > /sys/class/gpio_sw/PA10/data"))
its not work :( Why?
 

alexhi

Member
Licensed User
Hi Erel!
I have Orange PI PC board and
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)

When a do its:
sudo java -jar b4j-bridge.jar
I see


B4J-Bridge v1.00
Waiting for connections (port=6790)...
My IP address is: 192.168.0.220

When I start my app in IDE I see:

B4J-Bridge v1.00
Waiting for connections (port=6790)...
My IP address is: 192.168.0.220
Connected!
Starting program
ProcessCompleted

But I don't see myapp.jar in folder OrangePi

What could be wrong ? Thank you.
 

Cableguy

Expert
Licensed User
Hi guys,

Does anyone have an example of how to read a ds18b20 temperatura sensor with a raspi 2b?
 

Cableguy

Expert
Licensed User
Hi Roycefer,

Indeed I had, and I kind of understand what needs to be done and in wich order BUT I can't convert that thinking into code. Another factor is that my sensor is still on the mail.
 

Roycefer

Well-Known Member
Licensed User
Have you looked for code snippets that do what you want in other languages (Python, Arduino C, Java, etc...)? The forum could help you translate them into B4J. I haven't checked but there's gotta be something on Arduino.cc in the forums.
 

Cableguy

Expert
Licensed User
Have you looked for code snippets that do what you want in other languages (Python, Arduino C, Java, etc...)? The forum could help you translate them into B4J. I haven't checked but there's gotta be something on Arduino.cc in the forums.
Found out that 1wire is a simple serial protocol, and has been successfully implemented by using the Tx/Rx pins of an Arduino tied together... I'll keep on searching for more info...
 
Last edited:

Michael1968

Active Member
Licensed User
Found out that 1wire is a simple serial protocol, and has been successfully implemented by using the Tx/Rx pins of an Arduino tied together... I'll keep on searching for more info...
reading the ds18b20 with the pi in is no problem.
you only have to read the file: /sys/bus/w1/devices/28-xxxx

see reply #39

best regards Michael
 

Cableguy

Expert
Licensed User
Thanks Michael, I am aware of that approach, and if I can't find a direct "real-time" way to read the sensor, I will have to go with it.
I understand that the file is very small, but it will add to the SD read/write capability and reduce its life time.
 

MbedAndroid

Active Member
Licensed User
Someone has any idea why i get this error message?
got the lib installed in b4j lib
okt 19, 2015 9:54:47 AM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
java.lang.IllegalArgumentException: The path has to be absolute, but found: \lib\libpi4j.so
at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:120)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:174)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at b4j.example.main._appstart(main.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
main._appstart (java line: 45)
java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at b4j.example.main._appstart(main.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
 

MbedAndroid

Active Member
Licensed User
got a rasp now b2 version, run sudo java-jar b4j-bridge.jar, that works, got connection
still the same error runnng this example



Program started.
okt 28, 2015 7:11:56 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
java.lang.IllegalArgumentException: The path has to be absolute, but found: \lib\libpi4j.so
at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:120)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:174)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:637)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
at anywheresoftware.b4j.objects.GpioControllerWrapper.Initialize(GpioControllerWrapper.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:637)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Program terminated (StartMessageLoop was not called).
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 3 more
 
Top