I am doing a project where I use a compute module 3 with Raspbian Jessi Lite, Java with the Pi4J lib version 1.2-SNAPSHOT. I'm trying to implement a GpioPinListenerDigital on the GPIO_23 like so:

  public class SwitchAm {

    final GpioController gpio = GpioFactory.getInstance();
    final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RCMPin.GPIO_23, PinPullResistance.PULL_DOWN);



        GpioPinListenerDigital listener  = new GpioPinListenerDigital() {
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());


    boolean getState()
        return myButton.isHigh();

Sadly the listener is never called, but I can still get the correct GPIO state with getState.

I also tested the exact same code on a raspberry pi 3 model b and the listener is working perfectly.

What am I doing wrong?

  • Perhaps Pi4J doesn't work with the compute module? I suggest you raise an issue on the Pi4J site at github.com/Pi4J/pi4j/issues after checking the FAQ. – joan Mar 16 '18 at 12:55
  • The code I took was from the compute module section from pi4j.com so I hope it should work, maybe not for compute module 3. – lucblender Mar 16 '18 at 12:59

Your Answer

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

Browse other questions tagged or ask your own question.