pi4j | Java I/O library for Raspberry Pi

 by   Pi4J Java Version: release/1.4 License: Apache-2.0

kandi X-RAY | pi4j Summary

kandi X-RAY | pi4j Summary

pi4j is a Java library typically used in Internet of Things (IoT), Raspberry Pi applications. pi4j has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.

Java I/O Library for Raspberry Pi. [Maven Central] ![Snyk Security Badge] Project website: Pi4J Community Forum (new): Version 2.0 Project Discussions (new): Project issues list: Release builds are available from: * [Maven Central] * [Downloads] Snapshot builds are available from: * [Sonatype OSS] * [Downloads] Copyright 2012-2021 Pi4J. Please see the [BUILD.md] BUILD.md) instructions for details on how to compile/build this project.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              pi4j has a highly active ecosystem.
              It has 1272 star(s) with 468 fork(s). There are 161 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 28 open issues and 380 have been closed. On average issues are closed in 840 days. There are no pull requests.
              OutlinedDot
              It has a negative sentiment in the developer community.
              The latest version of pi4j is release/1.4

            kandi-Quality Quality

              pi4j has no bugs reported.

            kandi-Security Security

              pi4j has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              pi4j is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pi4j releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pi4j and discovered the below as its top functions. This is intended to give you an instant insight into pi4j implemented functionality, and help decide if they suit your requirements.
            • Loads a library .
            • Invoked when the pin state is pressed
            • Resize the buffer
            • The main entry point .
            • Executes an ioctl command .
            • Shuts down the GPIO pins .
            • Returns a SerialConfigConfig for the given arguments .
            • Get the default port for a given system type .
            • Handle a pin event
            • Helper method to create a cleanup task that can be used to cleanup any pending outputs .
            Get all kandi verified functions for this library.

            pi4j Key Features

            No Key Features are available at this moment for pi4j.

            pi4j Examples and Code Snippets

            No Code Snippets are available at this moment for pi4j.

            Community Discussions

            QUESTION

            Pi4j to use java with raspberry Pi not working
            Asked 2022-Feb-08 at 13:23

            I am honestly about to just give up, i've tried so many different possibilities, for multiple weeks now, almost a month, of multiple problems.

            I am a new-ish programmer, especially with java, but i have a good understanding about java

            I am able to create a maven project no problem, i have no problems with the structure of java itself, but i don't fully understand the pom.xml.

            The file compiles just fine, but when i go to start it with java -jar (filename), i get the following output;

            Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/Pi4J at com.pi.rasberri.Main.main(Main.java:16) Caused by: java.lang.ClassNotFoundException: com.pi4j.Pi4J at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ... 1 more

            Heres my pom that i have figuratively almost dismembered;

            ...

            ANSWER

            Answered 2021-Dec-18 at 16:39

            Thanks tgdavies, MadProgrammer, and khmarbaise for the answers, the fix was to create a fat jar, which is basically a jar file that contains all the dependencies in one file, example can be found in the original question/comments

            Now, as to the other problem, the issue is with this bit of code;

            Source https://stackoverflow.com/questions/70400115

            QUESTION

            how to get pH in Java using Grove - PH Sensor Kit (E-201C-Blue) Raspberry pi Zero and GrovePi Zero Board
            Asked 2022-Jan-31 at 21:14

            I have GrovePi Zero(GrovePi0) from GrovePi Zero Base Kit and Grove - PH Sensor Kit (E-201C-Blue) I am using Java (I can use any version of JDK 8...17) on a Raspberry Pi Zerro 2. with GrovePi-pi4j with Pi4j version 1.4 (can use any version)

            my class GrovePHSensor below represents the PH Sensor.

            ...

            ANSWER

            Answered 2022-Jan-24 at 11:40
            @GroveAnalogPin
            public class GrovePHSensor extends GroveAnalogInputDevice {
                 private static final Logger l = 
                 LogManager.getLogger(GrovePHSensor.class.getName());
                 /*** pH values range */
                 public static final double PH_RANGE = 14.0;
                /*** 
                  number of possible samples with 10 bit analog to digital converter 
                 */
                public static final int A2D_RANGE = 1023;
            
            public GrovePHSensor(GrovePi grovePi, int pin) throws IOException {
                super(grovePi.getAnalogIn(pin, 4));
            }
            
            @Override
            public Double get(byte[] data) {
                // the extraction of the value is taken from the sample of the 
                // RotarySensor3Led 
                // https://github.com/DexterInd/GrovePi/blob/master/Software/Java8/GrovePi-spec/src/main/java/org/iot/raspberry/grovepi/devices/GroveRotarySensor.java
                // this is how its is done there
            
                int[] v = GroveUtil.unsign(data);
                double sensorValue = (v[1] * 256) + v[2];
            
                // the Analog to Digital is 10 bit -> 1023 intervals that cover the range of pH of 0 to 14
                // hence the pH value is the sensor value that is 0 to 1024
                // times the pH per interval of the A2D 14/1023
                double ph = sensorValue * (PH_RANGE / (double) A2D_RANGE);
                l.trace("sensorValue = {}  ph={}", sensorValue, ph);
                return ph;
                }
            }
            

            Source https://stackoverflow.com/questions/70827164

            QUESTION

            Add a dependency from a maven project to a non-maven project
            Asked 2021-Nov-17 at 21:14

            I'm in the process of writing a java program for a Raspberry Pi where I want to access the GPIO. For this I use the Pi4J-Library Version 2 (https://pi4j.com). As IDE I use Visual Studio Code - as they suggest.

            In my VSC workspace are included:

            I can compile and package the minimal example application and my own project using the appropriate maven commands.

            Then I have a java library for desktop applications I wrote myself. I added this library and a project, that uses the library, to the workspace. I can run this desktop application from VSC. The library and the application where originally written using Eclipse. Maven is not involved.

            Now I'm trying to use a class from the desktop-library in my Pi4J-project: new MyLibClass

            VSC displays "MyLibClass cannot be resolved to a type". I have imported the class: import package.name.MyLibClass. Obviously the Pi4J-project doesn't know where to find the class. But when I CTRL-click the class name, it opens the corresponding file.

            I think I need to add a dependency to the pom.xml of my Pi4J-project. But I have absolutely no idea what to specify for groupId, artifactId and version. The desktop-library is not a maven project.

            Thanks a lot for your help in advance!

            ...

            ANSWER

            Answered 2021-Nov-17 at 21:14

            Maven supports three types of repository: local, central and remote. Normally, dependencies you add to your pom.xml file are pulled from the central repository. What you can do is compile your library to a jar, and drop that in your local repository, which can be found in one of the following locations depending on your OS:

            • Windows: C:\Users\\.m2
            • Linux: /home//.m2
            • Mac: /Users//.m2

            You can install your jar in your local repository as follows:

            Source https://stackoverflow.com/questions/70011329

            QUESTION

            How to control adressable RGB leds with raspberryPi in Java
            Asked 2021-Nov-16 at 21:12

            I have a strip of WS2811 adressable RGB leds and I am trying to control them using my raspberry pi. I am programming in java. To access the GPIO I am using a java library called Pi4j (version 1.2; java 8). This version has built-in PWM control.

            My question is the following: How can I send the data to the leds trough a GPIO pin?

            (I am still a beginner when it comes to physical computing, so please be gentle)

            ...

            ANSWER

            Answered 2021-Nov-16 at 21:12

            I haven't used NeoPixels directly on a Pi before (though I have many times used FadeCandy which is a USB LED controller that also does some nice dithering/frame blending).

            Driving NeoPixels isn't as straight forward as plain PWM on individual LEDs.

            There's a good Adafruit RaspberryPi NeoPixel wiring/coding tutorial. The notes on wiring/power are super useful. Even though the code is in Python, it's still useful to test/run.

            Having a quick look at the pi4j documentation, while it has all the "ingredients", it doesn't have built-in support for NeoPixels. Doing a quick search I spotted the diozero library which seems to have support for NeoPixels.

            I haven't tested diozero, but it's worth giving it a go.

            Source https://stackoverflow.com/questions/69995901

            QUESTION

            Eclipse projects no longer exporting runnable jar files
            Asked 2021-Mar-26 at 11:00

            Eclipse 2021-03 (4.19.0) on Windows 10 Pro (20H2) Raspberry Pi 4 running Raspbian 10 Java 11 (since it is the latest I've seen on the Raspberry Pi.

            I've recently encountered a problem while exporting runnable jar files. On new and older programs in the workspace, when they are exported as runnable jar files on the Windows 10 Pro and moved to the Raspberry Pi, I get the message "Error: An unexpected error occurred while trying to open file test.jar"

            Having written a "Hello World" program and exported it, it ran just fine. This leads me to believe it is something with the project name, the Maven repositories, some quirk on the Raspberry Pi, or some other unknown.

            The project names are now "ButtonMediaPlayerV24" where 24 indicates 2.4 (to keep previous versions, the period was removed in hopes it would fix the issue)

            The Maven Repositories are VLCj and pi4j.

            Have anything I should check or try?

            Tried: creating a new project, with the name "ButtonMediaPlayer" with the same result.

            UPDATE 1: After gutting the program and putting it into the test project, I found GPIO 30 and 31 had "PinPullResistance.PULL_DOWN" in the initiation, which was given as an error message after getting rid of the additional classes.

            UPDATE 2: The Maven repositories are not the problem, and the project name isn't an issue.

            Further updates if I find more.

            ...

            ANSWER

            Answered 2021-Mar-25 at 18:31

            The error appears to be the way I was trying to create local version control, which involved using Windows Explorer to create a new copy, and rename it. It seems to be possible to do this, but Eclipse must rename the file to update not obvious locations where the file name is. Without that, it seems to break every time.

            Source https://stackoverflow.com/questions/66804840

            QUESTION

            How to execute something every 10 seconds?
            Asked 2021-Jan-04 at 09:13

            I would like to execute a piece of code every 10 seconds. I have found an example on this forum, but have some issues with my implementation.

            ...

            ANSWER

            Answered 2021-Jan-03 at 18:04

            You need a class that extends TimerTask and override the public void run() method, which will be executed everytime you pass an instance of that class to timer.schedule() method.

            Source https://stackoverflow.com/questions/65553138

            QUESTION

            Raspberry Pi4 with Pi4j Java
            Asked 2020-Oct-30 at 08:42

            I am trying to run a simple test on my Raspberry Pi4 using the pi4j java library v1.2. Somehow it's not doing anything. I also don't see any errors on console. It just finishes after 2 seconds. I'm expecting the LED light to turn on and turn off after 2 seconds.

            I also updated my gpio binary to v2.52 as per this https://stackoverflow.com/a/63433316/607637 but it's still the same. Also, the command gpio write 19 1 is not doing anything.

            GPIO

            ...

            ANSWER

            Answered 2020-Oct-29 at 04:01

            It appears its answered here:

            It looks Pi4j is using a different pin numbering scheme. "Under the hood", WiringPi is used to control the GPIOs.

            So, I needed to tell it to use Broadcom pin numbering scheme using:

            GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));

            Now its working:

            Source https://stackoverflow.com/questions/64584365

            QUESTION

            Pi4j Event Listener not triggered by GPIO status change
            Asked 2020-Jan-25 at 11:18

            I have a simple Java program which should listen for changes of GPIO status.
            I'm using a button to change the status of a GPIO and from terminal I can see it works:


            Despite this, the event listener is never triggered. Here is the code:

            ...

            ANSWER

            Answered 2020-Jan-25 at 11:18

            Okay, apparently it was just me being stupid.
            The mistake is that I was using the class GpioPinDigitalOutput instead of GpioPinDigitalInput. I changed it and also modified this line

            Source https://stackoverflow.com/questions/59874213

            QUESTION

            Simple gradle build failing due to `package ... does not exist`
            Asked 2020-Jan-12 at 00:22

            A simple beginner project using an external library, that I can't get to build due to something basic I'm missing here. Thanks for your help.

            build.gradle

            ...

            ANSWER

            Answered 2020-Jan-12 at 00:22

            The com.pi4j:pi4j-parent dependency you declared is not a typical dependency you'd expect. It is the parent Maven POM for the Pi4J Project.

            If you view the contents of this dependency, you can see there are no published *.jar artifacts: https://repo1.maven.org/maven2/com/pi4j/pi4j-parent/1.2/

            Since there are no published JAR artifacts, you won't have anything on your classpath. What you need to do is declare the dependencies you need:

            Based on your imports, you'll want to pi4j-core package. So declare it as a dependency:

            Source https://stackoverflow.com/questions/59699529

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install pi4j

            You can download it from GitHub, Maven.
            You can use pi4j like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the pi4j component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/Pi4J/pi4j.git

          • CLI

            gh repo clone Pi4J/pi4j

          • sshUrl

            git@github.com:Pi4J/pi4j.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link