我试图通过Java点亮一个LED,但是当我运行我的项目时,我在输出中收到了这条消息:
wiringPiSetup: Unable to open /dev/mem: Permission denied
Unable to change ownership of /sys/class/gpio/gpio4/value: Operation not permitted
Unable to change ownership of /sys/class/gpio/gpio4/edge: Operation not permitted
如何获得使用GPIO引脚的访问权限?
程序:
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class HelloRPi
{
public static void main(String[] args) throws InterruptedException
{
System.out.println("Program started...");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin =
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, "REDLED", PinState.HIGH);
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// turn off gpio pin
pin.low();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
pin.toggle();
System.out.println("--> GPIO state should be: ON");
Thread.sleep(5000);
// toggle the current state of gpio pin (should turn off)
pin.toggle();
System.out.println("--> GPIO state should be: OFF");
Thread.sleep(5000);
System.out.println("--> GPIO state should be: ON for only 1 second");
pin.pulse(1000, true); // set second argument to 'true' use a blocking call
gpio.shutdown();
}
}
设置(RPi B +): (3V3)