B4J Library [IoT] jPi4J - Raspberry Pi GPIO controller

Discussion in 'B4J Libraries & Classes' started by Erel, Feb 5, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Which OS is running on the device?
     
  2. MbedAndroid

    MbedAndroid Active Member Licensed User

    raspian.....
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that it runs on the RasPi and not on the PC?

    Make sure that the IDE is connected to B4J-Bridge.

    You will get this exact error if you run it with B4J-Bridge disconnected (which means that it tries to run it on the PC).
     
  4. MbedAndroid

    MbedAndroid Active Member Licensed User

    it was connected....
    but i will retry as i used SSH. Will try it directly and let you know
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't matter whether you use SSH or not.

    The IDE should be connected:

    [​IMG]
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    BTW, you can see from the error message that it ran on Windows and not on Linux:
    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

    The forward slash is only used on Windows.
     
  7. MbedAndroid

    MbedAndroid Active Member Licensed User

    your're right erel :(
    with sudo java -jar b4j-bridge.jar it works...
    thanks !
    i think i missed the "connected" message
     
    Erel likes this.
  8. KMatle

    KMatle Expert Licensed User

    The RB has 8 digital inputs. With them we can check 8 switches (or even more with more boards).

    8 Bits represent 255 different values. For sure there is some hw to convert it but I don't know the word for it. Can someone help?

    My idea is to handle up to 255 switches with the 8 inputs.
     
  9. Roycefer

    Roycefer Well-Known Member Licensed User

    I think you're looking for a multiplexer. This will use up some of your digital outputs, as well.
     
  10. Cableguy

    Cableguy Expert Licensed User

    Search for multiplexer circuits/ ICs. as roycefer stated, some digital pins will be needed to control wich input to use.
    for example, a 1 to 16 mux uses 5 digital pins, 4 to select witch of the 16 inputs will be selected.
    So for 256 digital I/O you will need 8 control pins and another to retrieve the value.

    There may be other ways like cascading Muxes...

    You can also check non-traditional multiplexing techniques, like charlieplexing
     
    Last edited: Oct 30, 2015
    KMatle likes this.
  11. Michael1968

    Michael1968 Active Member Licensed User

    is a
    parallel-in/serial-out shift register a solution?

    74LV165A as an example
     
    KMatle likes this.
  12. Cableguy

    Cableguy Expert Licensed User

  13. KMatle

    KMatle Expert Licensed User

    Trying to run a 2x16 LCD display over my piFace 2 (via digital outputs). It has a serial in.

    I use these pins:

    PinFunction
    1Ground
    2Positive 5 volt
    3VEE (Connect to +5 and GND through 10k Pot for display contrast)
    4RS (Low for command - high for characters)
    5RW (Low for write - high for read)
    6E (Toggle to load data and command)
    7-14Data pins
    15Backlight +
    16Backlight Ground

    As I've understood by setting #6 from low to high and back the data is writen to the display.

    I try it with this code by setting the outputs:

    Code:
    Select seq
            
    Case 1
                e.State=
    True
                seq=seq+
    1
            
    Case 2
                d4.State=
    True
                d5.State=
    True
                d6.State=
    False
                d7.State=
    False
                rs.State=
    False
                rw.State=
    False
                seq=seq+
    1
            
    Case 3
                e.State=
    False
                seq=seq+
    1
            
    Case 4
                e.State=
    True
                seq=seq+
    1
            
    Case 5
                d4.State=
    True
                d5.State=
    True
                d6.State=
    False
                d7.State=
    False
                rs.State=
    False
                rw.State=
    False
                seq=seq+
    1
            
    Case 6
                e.State=
    False
                seq=seq+
    1
            
    Case 7
                e.State=
    True
                seq=seq+
    1
            
    Case 8
                d4.State=
    False
                d5.State=
    True
                d6.State=
    False
                d7.State=
    True
                rs.State=
    False
                rw.State=
    False
                seq=seq+
    1
    The code is crap but I wanted to try it. It's called by a timer (0,5secs). Am I totally wrong here or is it the right direction?
     
  14. Mark Turney

    Mark Turney Active Member Licensed User

    If no one else beats me to it, I'll try the same setup tomorrow and let you know what I get.
     
    KMatle likes this.
  15. Mark Turney

    Mark Turney Active Member Licensed User

    I just had a chance to solder wires to my 2x16 LCD. Will experiment a bit tonight and tomorrow.
     
  16. Mark Turney

    Mark Turney Active Member Licensed User

    I just realized that I'm not sure what you're trying to display, but I at least got mine to come on. Haven't soldered in quite a while ... forgot how good the fumes smell. LOL o_O ...

    Can you post the full code? If you don't want it public, just send me a private message and I will test for you. Thanks!
    IMG_3291.JPG
     
    KMatle and Erel like this.
  17. KMatle

    KMatle Expert Licensed User

    See here: http://www.b4x.com/android/forum/threads/solved-iot-raspberry-wiringpi-b4j-lcd-2x16.60252/

    It's all about the mapping. Take a look to the table (GPIO2 is not always PIN2). The working code is included.

    PS: Your display isn't conncected (except power) :D:D Maybe this will not work...
     
    Mark Turney likes this.
  18. Mark Turney

    Mark Turney Active Member Licensed User

    Ha ha ha on the "connections" comment .... for just a split second, I was going to clarify the pic until I realized that you were kidding ;)....
     
  19. HARRY

    HARRY Active Member Licensed User

    Hi,

    I am starting a project to communicate from my Raspberry with a I2c device. Starting point is the example by Erel in one of the posts in this thread. I think I am doing something totally wrong, but do not know what. I am not familiar with java objects. The program, up to now looks like

    Code:
    'Non-UI application (console / server application)
    #Region  Project Attributes
        
    #CommandLineArgs:
        
    #MergeLibraries: True
    #End Region

    Sub AppStart (Args() As String)
       
    End Sub


    Sub Process_Globals
        
    Dim bus As JavaObject = GetBus(1)
        
    Dim device As JavaObject = GetDevice(bus, 0)
    End Sub

    'Bus methods
    Sub GetBus(BusNumber As Int) As JavaObject
       
    Dim factory As JavaObject
       
    Return factory.InitializeStatic("com.pi4j.io.i2c.I2CFactory").RunMethodJO("getInstance"Array As Object(BusNumber))
    End Sub

    Sub GetDevice(bus As JavaObjectAddress As Int) As JavaObject
       
    Return bus.RunMethodJO("getDevice"Array As Object(Address))
    End Sub

    Sub CloseBus (bus As JavaObject)
       bus.RunMethod(
    "close"Null)
    End Sub

    'Device methods
    Sub Read(device As JavaObjectAs Int
       
    Return device.RunMethod("read"Null)
    End Sub

    Sub Read2 (device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int) As Int
       
    Return device.RunMethod("read"Array As Object(Buffer, Offset, Size))
    End Sub

    Sub Write(device As JavaObject, b As Byte)
       device.RunMethod(
    "write"Array As Object(b))
    End Sub

    Sub Write2(device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int)
       device.RunMethod(
    "write"Array As Object(Buffer, Offset, Size))
    End Sub
    When I do Compile and Run, I get a message:
    B4J version: 3.70 BETA 1
    Parsing code. Error
    Error parsing program.
    Error description: Parameter name cannot hide global variable name.
    Occurred on line: 27 (Main)
    Sub CloseBus (bus As JavaObject)

    and in the log:
    7* Parameter name cannot hide global variable name "
    and the text 'unused variable name 'device'

    What am i doing wrong?

    Harry
     
  20. Roycefer

    Roycefer Well-Known Member Licensed User

    You have global variables called "device" and "bus" and you also have parameters for subs called "device" and "bus". This isn't permitted. Either change the name of the global variables or change the name of the parameters.
     
    HARRY likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice