Android Things GpioCallback not received

I am trying to implement a button sample from simplepio . I made a connection as shown in schematics . After clicking the button, I do not receive the GPIO callback.

The code I use is the same as for the sample. Only exceptions "Initial activity" is printed in the journal

@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:

  • Make sure the circuit and button are functional by running pythonin raspbian jessiewith the 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 a button is clicked. So I'm sure that the button and GPIO pins on my PI are not a problem.

  • , , TextView TextView, TextView .
  • , onGpioEdge .

enter image description here

+4
3

wrong

, , , .

fritzing:

enter image description here

+3

, Button PI Android-, , .

ButtonInputDriver .

GPIO , . : https://github.com/androidthings/contrib-drivers/tree/master/cap12xx

ButtonInputDriver.

0

, , . , .

, Python, PI 3 , , .

, , - , GPIO .

Error on PeripheralIO API
    com.google.android.things.pio.PioException: android.os.ServiceSpecificException: BCM21 is already in use
       at com.google.android.things.pio.GpioImpl.<init>(GpioImpl.java:53)
       at com.google.android.things.pio.PeripheralManagerService.openGpio(PeripheralManagerService.java:169)
       at com.example.androidthings.simplepio.ButtonActivity.onCreate(ButtonActivity.java:129)
       at android.app.Activity.performCreate(Activity.java:6662)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6077)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
    Caused by: android.os.ServiceSpecificException: BCM21 is already in use
       at android.os.Parcel.readException(Parcel.java:1697)
       at android.os.Parcel.readException(Parcel.java:1636)
       at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.OpenGpio(IPeripheralManagerClient.java:776)
       at com.google.android.things.pio.GpioImpl.<init>(GpioImpl.java:51)
       at com.google.android.things.pio.PeripheralManagerService.openGpio(PeripheralManagerService.java:169at com.example.androidthings.simplepio.ButtonActivity.onCreate(ButtonActivity.java:129at android.app.Activity.performCreate(Activity.java:6662at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707at android.app.ActivityThread.-wrap12(ActivityThread.java) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460at android.os.Handler.dispatchMessage(Handler.java:102at android.os.Looper.loop(Looper.java:154at android.app.ActivityThread.main(ActivityThread.java:6077at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755
0

Source: https://habr.com/ru/post/1666832/


All Articles