B4J Question shell for GPIO Set on raspberry

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
How i can use this command with shell?
If i send this command
echo 1 > /sys/class/gpio/gpio21/value
or
echo 0 > /sys/class/gpio/gpio21/value
with a putty session while run my b4j program on raspberry p2 this work fine, but with shell by b4j code not work.

B4X:
Dim js As  Shell
js.Initialize("", "echo", Array As String(">", "1", "/sys/class/gpio/gpio21/value"))
js.Run(-1)
or
B4X:
Dim js As  Shell
js.Initialize("", "echo 1 >", Array As String("/sys/class/gpio/gpio21/value"))
js.Run(-1)

How i format this command with shell?

Thi commad as example work
B4X:
Dim js As  Shell
js.Initialize("", "aplay", Array As String(File.DirApp & "/Audio/" & clip))
js.Run(-1)

Thanks
 

Roycefer

Well-Known Member
Licensed User
Longtime User
In your first code snippet, the arguments are in the wrong order in the "Array As String" part. I'm not sure this will solve your problem, but it surely isn't helping. If this doesn't fix it, you should see if jShell is running in a .jar that has the same or higher access level as your putty session.

Also, is there any particular reason why you're trying to use jShell to access the GPIO rather than the jPi4J library? Surely the latter will be a lot easier.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
I tried with jPi4J but does not work, maybe because my application is UI?
Now i testing this only in debug mode.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

a simple example, using the jPi4J Library and tested on a RPi via the B4J-Bridge, to switch a pin state via app commandline argument.
Although a B4J Non-UI app, it is a proper way of testing the jPi4J library and of course the RPi wiring.

B4X:
#Region  Project Attributes
   #CommandLineArgs: on
   #MergeLibraries: true
#End Region

Sub Process_Globals
    Private controller As GpioController
    Private Pin1 As GpioPinDigitalOutput
    Private PinState As Boolean = False
End Sub

Sub AppStart (Args() As String)
    Try
        controller.Initialize
    Catch
        Log("Controller Initialize Error:" & CRLF & LastException.Message)
        Return
    End Try
    If Args(0).ToLowerCase = "on" Then
        PinState = True
    Else
        PinState = False
    End If
    Pin1.Initialize(1, PinState)
    Log("Pin1 state changed to " & PinState)
    ExitApplication
End Sub
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Ok Tanks to all, it works both ways.
It's my fault for bad assignment pin number (21 is 29). :oops:
 
Upvote 0
Top