Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Things GpioCallback not received

I am trying to implement the button sample from simplepio. I have made the connection as shown in schematics. After pressing the button I do not get the GPIO callback.

Code I am using is same as that of sample. There are no exceptions only "Starting Activity" gets print in log

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting ButtonActivity");

    PeripheralManagerService service = new PeripheralManagerService();
    try {
        String pinName = BoardDefaults.getGPIOForButton();
        mButtonGpio = service.openGpio(pinName);
        mButtonGpio.setDirection(Gpio.DIRECTION_IN);
        mButtonGpio.setEdgeTriggerType(Gpio.EDGE_FALLING);
        mButtonGpio.registerGpioCallback(new GpioCallback() {
            @Override
            public boolean onGpioEdge(Gpio gpio) {
                Log.i(TAG, "GPIO changed, button pressed");
                // Return true to continue listening to events
                return true;
            }
        });
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    }
}

What I have tried so far:

  1. Verified that the circuit and button are functional by running a python button program in raspbian jessie with following code

    #!/usr/bin/env python
    
    import os
    from time import sleep
    
    import RPi.GPIO as GPIO
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP)
    
    while True:
        if (GPIO.input(21) == False):
            print("Button Clicked")
    
        sleep(0.1)
    

    The above code prints "Button Clicked" when button is pressed. So I am sure that the button and GPIO pins on my PI are not an issue.

  2. To make sure there is no issue with logging I also tried modifying the original program to contain a TextView and a counter so as when a button is clicked the counter value is incremented and displayed in TextView but again the callback wasn't received and TextView wasn't updated.
  3. Tried different edge trigger type but onGpioEdge is never called.

Following is the picture of my setup

enter image description here

like image 373
Anirudha Agashe Avatar asked Oct 17 '22 18:10

Anirudha Agashe


1 Answers

Is it just me or is your resistor in the wrong breadboard row

wrong

The arrow shows where it is, the circle shows where it should be.

According to the fritzing diagram:

enter image description here

like image 175
Blundell Avatar answered Oct 21 '22 09:10

Blundell