1

I am running the code at the bottom using java and Pi4j library, pretty much the program checks is the pin is low and waits sometime before turning off the tv.

When I reboot my Raspberry and run the code, I get no issues. however when I close the program using CTR+C and run again, sometimes I get the this error when I start the program, and I cannot read from the sensor :

wiringPiSetup: mmap failed: No such file or directory

and also the following error

file:/opt/jdk1.8.0/jre/lib/ext/jfxrt-controls.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
Exception in thread "Thread-5" java.lang.NullPointerException
at javafxapplication4.JavaFXApplication4.lambda$0(JavaFXApplication4.java:672)
at javafxapplication4.JavaFXApplication4$$Lambda$3.run(Unknown Source)
at java.lang.Thread.run(Thread.java:724)

and my code is

 new Thread(() -> {
            final GpioController gpioSensor = GpioFactory.getInstance();
            sensor_lastTimerCall = System.currentTimeMillis();
            final GpioPinDigitalInput sensor = gpioSensor.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);
            sensor.addListener(new GpioPinListenerDigital() {
                @Override
                public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                    if (event.getState().isHigh()) {
                        sensor_lastTimerCall = System.currentTimeMillis();
                        ProcessBuilder processBuilder1 = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI");
                        try {
                            Process process1 = processBuilder1.start();
                        }catch (IOException ex) {
                            Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex);
                        }   
                    }
                    if(event.getState().isLow()){sensorLow = true;}
                }
            });
            System.out.println(" ... Motion Detection Starting.....");

            for (;;) {
                try {
                    Thread.sleep(1000);
                    long now = System.currentTimeMillis();
                    if (System.currentTimeMillis() > sensor_lastTimerCall + 360000 && sensorLow) {
                        System.out.println("All is quiet...");
                        ProcessBuilder processBuilder2 = new ProcessBuilder("bash", "-c", "echo \"standby 0000\" | cec-client -d 1 -s \"standby 0\" RPI");
                        try {
                            Process process2 = processBuilder2.start();
                        }catch (IOException ex) {
                            Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        sensor_lastTimerCall = now;
                        sensorLow = false;
                    }
                } catch(InterruptedException ex) {
                    gpioSensor.shutdown();
                    Thread.currentThread().interrupt();
                }
            }

        }).start();

    }

any idea how to fix this?

  • apparently the sensor was reading but the errors come up once a while but still able to read., – Ossama Mar 10 '14 at 6:46
  • Can you indicate the line numbers in your program. It looks like the error is happening at line 672 but we can't tell where that is from the information provided. – Kolban Apr 12 '15 at 22:18
1

I get the same problem but only when I shutdown and restart the program right away. I put a one second delay before getting the gpio instance. You can check for null and try again as needed, but it hasn't failed since.

    // create gpio controller
    log("trying to get gpio controller... ");
    Thread.sleep(1000);
    final GpioController gpio = GpioFactory.getInstance();
    if (gpio != null)
        log("opened gpio controller");
    else {
        //try again later if you want 
        log("failed to get gpio controller");
        System.exit(1);
    }
0

1.- you can check u have pi4j correct installed into the project 2.- try to use PinPullResistance.PULL_UP 3.- comment all other code but what u need to check if pin is working, so you can check if that pin is working as expected. 4.- i can give u an example for me is workin:

//SETUP gpio = GpioFactory.getInstance( ); GpioPinDigitalInput rigthPad; //gpio 23 rigthPad = gpio.provisionDigitalInputPin( RaspiPin.GPIO_23, PinPullResistance.PULL_UP );

//add listener like u have above //finally implement GpioPinListenerDigital

i dont recall if you have to change the configuration first

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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