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.
My pom.xml, I am using Pi4J v2:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Pi_SmartHomeLogic</groupId>
<artifactId>Pi_SmartHomeLogic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>app.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!--<repository> -->
<!-- <id>caarmen-repo</id>-->
<!--<url>https://dl.bintray.com/caarmen/maven/</url> -->
<!--</repository> -->
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>ca.rmen</groupId>
<artifactId>lib-sunrise-sunset</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.zeroone3010</groupId>
<artifactId>yetanotherhueapi</artifactId>
<version>2.6.0</version>
</dependency>
<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>
</dependencies>
</project>
Since Pi4J does no longer use wiringPi, it uses the BCM address instead, so I dont get why it doesnt work?