User avatar
Douglas6
Posts: 5110
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Basic problems with pi4j (solved)

Sun May 26, 2013 11:04 pm

Running the 2013-02-09 wheezy raspian image, and installing either pi4j 0.0.5 or 1.0.0-SNAPSHOT, when running the example or trying to use it in my own code, I'm getting the following

Code: Select all

sudo java -classpath .:classes:/opt/pi4j/lib/'*' ControlGpioExample
<--Pi4J--> GPIO Control Example ... started.
Exception in thread "main" java.lang.RuntimeException: Unable to open GPIO direction interface for pin [1]: No such file or directory
        at com.pi4j.wiringpi.GpioUtil.export(Native Method)
        at com.pi4j.io.gpio.RaspiGpioProvider.export(RaspiGpioProvider.java:67)
        at com.pi4j.io.gpio.impl.GpioPinImpl.export(GpioPinImpl.java:165)
        at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:520)
        at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:645)
        at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:672)
        at com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControllerImpl.java:684)
        at ControlGpioExample.main(ControlGpioExample.java:52)
I subsequently installed wiringPI itself, and have no problem running gpio commands. Any help, please?

rickz
Posts: 5
Joined: Sat Apr 06, 2013 1:33 am
Location: California

Re: Basic problems with pi4j

Mon May 27, 2013 4:46 am

The following line works for me.

Code: Select all

sudo java -cp .:/opt/pi4j/lib/pi4j-core.jar ControlGpioExample

User avatar
Douglas6
Posts: 5110
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

[mostly SOLVED] Basic problems with pi4j

Mon May 27, 2013 4:24 pm

Problem solved, mostly. For an earlier project, I had loaded the lirc_dev and lirc_rpi modules, which by default use the same pin (GPIO_01 = BCM GPIO18 = P1 header pin 12) as the pi4j example. Unloading these modules (and disabling init.d/lirc) fixed the problem with pi4j.

I don't understand why pi4j complains when the wiringPi gpio command does not, but for now I don't need lirc, so I'm golden.

catstevens
Posts: 8
Joined: Fri Sep 27, 2013 10:51 pm

Re: Basic problems with pi4j (solved)

Sun Jan 26, 2014 6:02 pm

use lsmod to display all modules loaded by the kernel

lsmod | grep lirc_dev

if it loaded

rmmod lirc dev
rmmod lirc_rpi

and your program will run correctly. have fun

bellaj badr

User avatar
Douglas6
Posts: 5110
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Basic problems with pi4j (solved)

Sun Jan 26, 2014 6:09 pm

Pretty much exactly what I did, way back when, thanks.

Return to “Java”