Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
273 stars 57 forks source link

java.lang.ClassNotFoundException: com.pi4j.library.pigpio.PiGpio #214

Closed razorne closed 2 years ago

razorne commented 2 years ago

Hello,

i am new to the library and i am trying to make a led blink. I have written a short code, copying from the tutorial page on official website.

public static void main(String[] args) throws InterruptedException {
        int PIN_LED = 22;
        var pi4j = Pi4J.newAutoContext();
        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);

        led.low();
        Thread.sleep(1000);
        led.high();
        Thread.sleep(1000);
        pi4j.shutdown();
}

I am not using maven nor gradle to package the program (i am a maven user, but for this project, for reasons that are not relevant, i cannot use it) I run the program directly from the raspberry, using this sh:

java - cp "/home/rasp/project35/lib/*:/home/rasp/project35/dist/*" com.project35.Main

And this is the content of those folders. As you can see i am using the version of dependencies that are used in the official getting started page.

2022-04-23-133633_1920x1080_scrot

2022-04-23-133717_1920x1080_scrot

I am using JDK 11 since i have installed the Raspberry Pi OS Full (32-bit), just like suggested by the getting started page.

Am i missing something here?

Thanks

savageautomate commented 2 years ago

I think you may be missing one or more transitive dependencies. The library JAR pi4j-library-pigpio-2..0.jar appears to be missing. Also you must have the PiGpio library installed on your Rpi. See: https://abyz.me.uk/rpi/pigpio/download.html

razorne commented 2 years ago

Thank for your comment. Yes i was missing that dependency, by adding it, and executing my sh as sudo (otherwise i would have received another error) i was able to make my led blink

savageautomate commented 2 years ago

Yes, sudo is required for using the PiGpio provider. I'm working on Linux GPIO (filesystem) providers now that don't require sudo access.

See: https://github.com/Pi4J/pi4j-v2/issues/212

razorne commented 2 years ago

Very nice! Thank you