Hello guys i need your help so i want to use the raspberry pi with java in eclipse so i can turn on and off a led first and then i will add a frame with a button to turn on and off.
the problem is my pi4j. jar is not accessable and the import com.pi4j.io.gpio.GpioController; is not found because the import com.pi4j.io.gpio.GpioControlle there is no gpiocontroller.jar file or other jar files i need in the pi4j libary but it should be and i dont find a pi4j libary with in it ? ( to understand there are in the zip file all 10 jar files which i add)
i use the java openjdk 11 with the pi4j 2 version i also tried the 1.4 verision and i dont know the problem how i can run the programm without a error ?
so if you could help me it would be awesome i am a beginner and this is my first try
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.RaspiPin;
public class Main {
public static void main(String[] args) throws InterruptedException {
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_17);
ledPin.high();
Thread.sleep(5000);
ledPin.low();
gpio.shutdown();
}
}
-
- Posts: 12
- Joined: Mon Dec 09, 2019 9:13 pm
Re: pi4j in eclipse
Hi, the best would be to start with Pi4J V2.
This example shows the first steps: https://pi4j.com/getting-started/minima ... plication/
The sources of the full project with both Maven and Gradle files can be found here: https://github.com/Pi4J/pi4j-example-minimal
If you prefer to start experimenting with a single Java-file, JBang is a great way to do this.
Full example is available on https://pi4j.com/documentation/building/jbang/
Frank
This example shows the first steps: https://pi4j.com/getting-started/minima ... plication/
The sources of the full project with both Maven and Gradle files can be found here: https://github.com/Pi4J/pi4j-example-minimal
If you prefer to start experimenting with a single Java-file, JBang is a great way to do this.
Full example is available on https://pi4j.com/documentation/building/jbang/
Frank
Re: pi4j in eclipse
FrankDelporte wrote: ↑Tue Jan 24, 2023 7:43 amHi, the best would be to start with Pi4J V2.
This example shows the first steps: https://pi4j.com/getting-started/minima ... plication/
The sources of the full project with both Maven and Gradle files can be found here: https://github.com/Pi4J/pi4j-example-minimal
If you prefer to start experimenting with a single Java-file, JBang is a great way to do this.
Full example is available on https://pi4j.com/documentation/building/jbang/
Frank
Thanks for helping but do i need a maven or gardle file to run a projekt like this ? Or can i use only pi4j ? Is this the fail i hve that i dont use maven and gardle ?
-
- Posts: 12
- Joined: Mon Dec 09, 2019 9:13 pm
Re: pi4j in eclipse
I always use Maven 
Anyhow you need to make sure you have all required dependencies and initialize Pi4J context in the right way, see https://pi4j.com/getting-started/minima ... plication/
Dependencies:
Pi4J context:

Anyhow you need to make sure you have all required dependencies and initialize Pi4J context in the right way, see https://pi4j.com/getting-started/minima ... plication/
Dependencies:
Code: Select all
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- include Pi4J Core -->
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>${pi4j.version}</version>
</dependency>
<!-- include Pi4J Plugins (Platforms and I/O Providers) -->
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
<version>${pi4j.version}</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-pigpio</artifactId>
<version>${pi4j.version}</version>
</dependency>
</dependencies>
Code: Select all
var pi4j = Pi4J.newAutoContext();
private static final int PIN_LED = 22; // PIN 15 = BCM 22
var ledConfig = DigitalOutput.newConfigBuilder(pi4j)
.id("led")
.name("LED Flasher")
.address(PIN_LED)
.shutdown(DigitalState.LOW)
.initial(DigitalState.LOW)
.provider("pigpio-digital-output");
var led = pi4j.create(ledConfig);
while (true) {
if (led.equals(DigitalState.HIGH)) {
led.low();
} else {
led.high();
}
Thread.sleep(500);
}
Re: pi4j in eclipse
Ok i will try this thanks what do i wrong when the wiringpi library is not implemented and the dynamics
?
Or can i solce this problems if i use the jdk 19 with a 19 compiler and the pi4j with maven ?
I hope this is correct what i say
?
Or can i solce this problems if i use the jdk 19 with a 19 compiler and the pi4j with maven ?
I hope this is correct what i say

-
- Posts: 12
- Joined: Mon Dec 09, 2019 9:13 pm
Re: pi4j in eclipse
V2 of Pi4J doesn't use WiringPi anymore as that has been deprecated some years ago and doesn't support the latest Pi versions...
Java 19 shouldn't be a problem!
Java 19 shouldn't be a problem!