Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 448 forks source link

Raspberry Pi 4 loses connection when using Pi4J to monitor GPIO inputs #525

Closed CJure closed 3 years ago

CJure commented 3 years ago

I have simple GUI application where I want to monitor status of two GPIOs. If I run just GUI without Pi4J code everything works fine, but with GUI code Pi loses network connection over Ethernet port and I have to restart it. Code:

 try
        {
            //sound gpio = 23, move = 17
            final GpioController gpio = GpioFactory.getInstance();
            final GpioPinDigitalInput soundSensor = gpio.provisionDigitalInputPin(RaspiPin.GPIO_23, PinPullResistance.PULL_DOWN);
            final GpioPinDigitalInput moveSensor = gpio.provisionDigitalInputPin(RaspiPin.GPIO_17, PinPullResistance.PULL_DOWN);
            moveSensor.setShutdownOptions(true);
            soundSensor.setShutdownOptions(true);
            final Main main = new Main();

            moveSensor.addListener(new GpioPinListenerDigital() {
                @Override
                public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                    // display pin state on console
                    System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());
                    main.jCheckBoxMove.setSelected(event.getState().isHigh());
                }
            });

            soundSensor.addListener(new GpioPinListenerDigital() {
                @Override
                public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                    // display pin state on console
                    System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());
                    main.jCheckBoxSound.setSelected(event.getState().isHigh());
                }
            });
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            System.out.println("Exception on main: " + ex.toString());
        }

If I run similar code in Python I have no problems.

savageautomate commented 3 years ago

Which pin is GPIO 17?
See: https://pi4j.com/1.3/pins/rpi-4b.html

I think pins 17 to 20 were on the earlier models that included the P5 8-pin expansion header. https://pi4j.com/1.3/pins/rpi-1b-rev2.html

If you meant BCM pin #17, then that would be GPIO 0 in Pi4J/WiringPi.

Untitled

CJure commented 3 years ago

Thank you for quick response. You are correct I was using BCM pins and it looks that this caused that Ethernet connection would disconnect..