B4J Question Use of GPIO on Raspberry

Discussion in 'B4J Questions' started by HARRY, Mar 28, 2015.

  1. HARRY

    HARRY Active Member Licensed User

    Hi ,

    I am trying to connect a LED to my RaspBerry; the new one B2. I am using pin 1, which is physically pin 28 as far as I can find from the documentation.

    I didn't get it working and thought that possibly the jPi4J library or one of its underlaying components was not up to date. Finally I found an update for the WiringPi library to cope with the changed board lay-out of the B2 board. I installed that update.

    Now I get the message below when I start my B4J program.

    Program started.
    (ArrayList) [/dev/ttyUSB0]
    Mar 28, 2015 6:32:18 PM com.pi4j.util.NativeLibraryLoader loadLibraryFromResource
    WARNING: The temporary file already exists [/tmp/libpi4j.so]; attempting to delete it now.
    Must be root to call wiringPiSetup().
    (Did you forget sudo?)

    I installed everything as sudo.

    I do not know what to do. Can somebody help me?

  2. giga

    giga Well-Known Member Licensed User

    How many users do you have setup? Also are you currently logged in as root?
  3. Erel

    Erel Administrator Staff Member Licensed User

    Peter Simpson likes this.
  4. rwblinn

    rwblinn Well-Known Member Licensed User


    pls find a documented B4J non-UI example project here. There are numerous hints in the project file.

    Also check if wiringPi is setup correctly on the Raspberry Pi: Find hints here , goto Raspberry Pi > WiringPi usage
    ellpopeb4a likes this.
  5. HARRY

    HARRY Active Member Licensed User

    Hi helpers,

    Starting b4j-bridge as sudo makes everything work. I think that without using WiringPi it didn't matter how to start b4j-bridge. But I am not sure. Will figure out later on.

  6. HARRY

    HARRY Active Member Licensed User


    Still struggling with GPIO. When I use the sample rwblinn is referring to, the program runs, but the LED does not light and the log shows continuously:"Switching Pin1 state. Pin1 state = true." I use the RaspBerry board model 2. According to the documentation the physical pin for 1 in Pin1.Initialize(1, True) is 12.
    Does somebody have an idea what can be wrong?

  7. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Harry,

    have tested again and my sample is running fine. Pls ensure:
    The LED is connected to Pin 1. Pin 1 Is set As an output pin. Pin 1 Is the physical Pin 12 on the RPi which Is called GPIO18.

    IMPORTANT NOTE: Ensure you have downloaded the latest Pi4J jar files from here.

    Last edited: Mar 31, 2015
  8. HARRY

    HARRY Active Member Licensed User

    Hi Rob,
    Thanks for your reply. I am new to java environment. I downloaded http://get.pi4j.com/download/pi4j-1.1-SNAPSHOT.deb to my raspberry and unpacked it to control.tar.gz, data.tar.gz, debian-binary and _gpgbuilder. Sorry, but what next?

  9. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Harry,

    you need to download the zip file to your PC.
    From the zip file copy following jar files to the B4J additional library folder: pi4j-core, pi4j-device, pi4j-gpio-extension.
    Ensure you also have the jPi4J.jar and xml in your B4J additional library folder.

    To run:
    On the RPi start the B4J bridge: $sudo java -jar b4j-bridge.jar. Note the IP address.
    On the PC start the B4J IDE, connect to B4J Bridge using the noted IP address. In the IDE bottom left, connected is displayed.
    Run the app by pressing F5 ... and the LED should flash every 5 seconds.

    Good Luck,
  10. HARRY

    HARRY Active Member Licensed User


    Many thanks. It works now as it should.

    rwblinn likes this.
  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