0

I am trying to get the Pi4J library to work on my Raspberry Pi 4. I just wrote a simple blink program. It is not toggling the pin as it should be.

Here is the simple program. I have compiled it, and it compiles fine and runs showing the state of the pin, logically. However, the pin is not going high when hooked up to a multimeter.

I am wondering if there is some system setting that is blocking the control of the GPIO pins from this library.

A little bit of info ... I am running Raspberry Pi OS full version. I am fully upgraded and updated. I am using Java 11. And I downloaded the latest Pi4J library as of last week.

    public class GPIOTest { 
      public static void main (String[] args) {
        Context pi4j = Pi4J.newAutoContext();
    
        DigitalOutput dirLeft = pi4j.dout().create(14);
    
        System.out.println(pi4j.getClass().toString());
        System.out.println(dirLeft.getClass().toString());
    
        while (true){
          System.out.println("Setting pin low.");
        
          dirLeft.low();
        
          System.out.println(dirLeft.state());
        
          try {
            Thread.sleep(5000);
          } catch (InterruptedException e) {
            // Do nothing.
          } 
        
          System.out.println("Setting pin high.");
        
          dirLeft.high();
                    
          System.out.println(dirLeft.state());

          try {
            Thread.sleep(5000);
          } catch (InterruptedException e) {
            // Do nothing.
          } 
        }
      }
    }

Simple blink wiring

1
  • Add a photo showing the (wrong) connections you have made.
    – joan
    Commented Aug 17, 2022 at 6:35

1 Answer 1

1

I finally resolved the issue. I am not using Pi4J.

I wrote a simple Python script that takes care of the GPIO behavior of the system that I designed and called the script from Java. (I was not about to rewrite the rest of the system in Python, that would have just been a waste of time.)

If anyone has a solution to the question beyond this, please share. I am still willing to learn more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.