0

I am trying to use my Raspberry Pi 4's GPIOs to turn on various thing in my smart home.

I am getting 2.6V on the GPIO Input, thus resulting in a HIGH signal. I have confirmed this with a basic python script, but since I am better in Java and I want to use some APIs, I wanted to use Java and thus Pi4J.

Whatever I am doing however, the Inputs are never changing their state. Or rather, the Listener for the input is never triggered. But the console does print statements generally, the console works.

Here my code:

public class App {

private final static int inputOne = 27; // PIN 13, address 27
private final static Context pi4j = com.pi4j.Pi4J.newAutoContext();

public static void main(String[] args) throws InterruptedException, IOException {
    final Console console = new Console();
    console.promptForExit();
    // I/O Config Build
    var isInput = DigitalInput.newConfigBuilder(pi4j).id("0").name("inputOne").address(inputOne)
            .pull(PullResistance.PULL_DOWN).debounce(3000L).provider("pigpio-digital-input").build();

    // I/O Build
    var inputOne = pi4j.din().create(isInput);


    inputOne.addListener(e -> {
        if (e.state() == DigitalState.HIGH) {
            console.print("input high");
        } else {

        }
    });
    console.waitForExit();
    pi4j.shutdown();
}

} I have also tried using the Board address of the pin instead of the board layout, did result in nothing as well.

These are my dependencies, I am using Pi4J v2:

<dependency>
    <groupId>com.pi4j</groupId>
    <artifactId>pi4j-core</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>com.pi4j</groupId>
    <artifactId>pi4j-gpio-extension</artifactId>
    <version>1.3</version>
</dependency>
<dependency>
    <groupId>com.pi4j</groupId>
    <artifactId>pi4j-plugin-raspberrypi</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>com.pi4j</groupId>
    <artifactId>pi4j-plugin-pigpio</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.36</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.36</version>
</dependency>

Since Pi4J does no longer use wiringPi, it uses the BCM address instead, so I dont get why it doesnt work?

2
  • "Since Pi4J does no longer use wiringPi" what does it use? I am not a Java programmer but I would write a simple program to test output & input. PS I wrote a program to monitor pins raspberrypi.stackexchange.com/a/123749/8697 which is independent of any library which you could use for debugging.
    – Milliways
    Aug 1 at 1:47
  • @Milliways As I wrote, it uses the BCM addresses now. I will check out your program later, thanks
    – Dahlin
    Aug 1 at 7:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.