pi4j-v2
pi4j-v2 copied to clipboard
Pi 4B crashes if trying to attach a listener to all GPIO pins
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);
}
}
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.