Ani*_*she 5 raspberry-pi raspberry-pi3 android-things
我正在尝试从simplepio实现按钮示例.我已经如原理图所示建立了连接.按下按钮后,我没有得到GPIO回调.
我使用的代码与示例代码相同.没有例外,只有"启动活动"在日志中打印
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试了什么:
通过使用以下代码运行python按钮程序,验证电路和按钮是否正常工作
raspbian jessie
#!/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)
Run Code Online (Sandbox Code Playgroud)
按下按钮时,上面的代码打印"按钮单击".所以我确信我的PI上的按钮和GPIO引脚不是问题.
TextView和一个计数器,以便当单击一个按钮时,计数器值会递增并显示,TextView但是再次没有收到回调并且
TextView没有更新.以下是我的设置图片
我发现 Button 驱动程序在带有 Android 设备的 Raspberry PI 上非常不可靠,毕竟驱动程序与您拥有的代码几乎相同。
然而,ButtonInputDriver 工作得非常完美。
事实上,您不需要直接寻址GPIO,可以使用驱动层,这样更简单。按钮驱动程序在这里:https ://github.com/androidthings/contrib-drivers/tree/master/cap12xx
我建议你尝试一下 ButtonInputDriver。
| 归档时间: |
|
| 查看次数: |
1454 次 |
| 最近记录: |