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;
}
});
} 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
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 .
