pi4j-v2 icon indicating copy to clipboard operation
pi4j-v2 copied to clipboard

Pi 4B crashes if trying to attach a listener to all GPIO pins

Open lukehutch opened this issue 4 years ago • 1 comments

This piece of code crashes the Pi 4B:

for (int pin = 0; pin < 31; pin++) {
    try {
        int pinNum = pin;
        DigitalInput digitalInput = Bonnet.pi4j
                .create(DigitalInput.newConfigBuilder(Bonnet.pi4j).id("gpio-pin-" + pin).name("Pin #" + pin)
                        .address(pin).pull(PullResistance.PULL_UP).build());
        digitalInput.addListener(new DigitalStateChangeListener() {
            @Override
            public void onDigitalStateChange(DigitalStateChangeEvent event) {
                System.out.println("GPIO pin " + pinNum + " state change");
            }
        });
    } catch (Exception e) {
        System.err.println("Could not set up digital input " + pin + ": " + e);
    }
}

lukehutch avatar Nov 22 '20 04:11 lukehutch

I narrowed it down -- it's pin numbers 28 and 29 that cause the crash, even with nothing plugged into the GPIO header. The Pi locks up hard, and has to be power cycled.

lukehutch avatar Nov 22 '20 04:11 lukehutch