-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button driver #120
Comments
Any chance you can share an image of how things are plugged in?
…On Sun, Jan 6, 2019, 7:45 AM Yoey ***@***.***> wrote:
Button presses are only recognized once. Only after a device reboot is a
button press recognized again.
I followed the sample code usage from the readme, and inserted this into
the onCreate() method to setup the button on device launch
pButton = new Button(GPIO_P_BUTTON, Button.LogicState.PRESSED_WHEN_HIGH);
pButton.setOnButtonEventListener(new Button.OnButtonEventListener() {
@OverRide
public void onButtonEvent(Button button, boolean pressed) {
doStuff();
}
That code is obviously surrounded by a try/catch block.
I've added this to my module build.gradle file:
compile 'com.google.android.things.contrib:driver-button:1.0'
And this to my onDestroy method
if(pButton != null){
pButton.close();
}
I tried different GPIO pins, different cables and different buttons.
Always the same result.
Any idea what I could do to change that behavior?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#120>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACOhb9yHjm2f6ZlkmxDcpZOVmeWycpX_ks5vAgwUgaJpZM4ZydHD>
.
|
@YoeyHD In your photo, your button seems to be lacking some connections. With electrical switches (such as buttons), you need an additional connection on the output side (the side that goes to your GPIO) to "pull" the signal towards either power or ground, whichever is opposite the signal on the input side. For example, take a look at the button on this diagram from one of our samples. Notice the input side of the button connects directly to ground. On the output side, there are 2 connections: one to the GPIO, and one to 5V using a resistor. This is a pull-up resistor. When the button is not being pressed, the GPIO signal is being pulled up to 5V. (You could also swap 5V and ground to make a button that gets pulled down.) Without a pull-up or pull-down resistor, the GPIO signal can "float" somewhere between high and low, which produces unintended behavior. Try connecting your button like the diagram and see if that helps. (This may not be your only issue, but it's worth fixing just so you can rule it out.) |
It works! Thanks a lot! Since this is my first time with GPIO and everything, is there a way to trigger doStuff() once? Right now, it triggers more than once, usually twice. Sometimes even more, especially if I keep the button pressed for a longer period of time. The latter behavior wouldn't be such an issue. However, the former would be an issue |
@YoeyHD You can check the value of It also may depend on what resistor value you are using... I think most of the time I was using 10K resistors and typically didn't see a press register twice. Of course, that's not as foolproof as checking for a value change in the callback. |
Button presses are only recognized once. Only after a device reboot is a button press recognized again.
I followed the sample code usage from the readme, and inserted this into the onCreate() method to setup the button on device launch
That code is obviously surrounded by a try/catch block.
I've added this to my module build.gradle file:
And this to my onDestroy method
I tried different GPIO pins, different cables and different buttons. Always the same result.
Any idea what I could do to change that behavior?
The text was updated successfully, but these errors were encountered: