我想用Android物件和树莓派3开启LED。我按照https://developer.android.com/things/sdk/pio/gpio的指示进行了操作。我正在使用最新的Android Things版本(1.0.15)。任何评论为什么我会出现这样的错误?
2009-01-01 03:30:07.762 667-667 / com.inflashpay.inflashE / Request权限:可用端口列表:[BCM2] 2009-01-0103:30:07.774 667-667 / com.inflashpay.inflash E / Request权限:无法访问GPIOcom.google.android.things.pio.PioException:android.os.ServiceSpecificException:BCM2无法应用所需的PIN MUX:无此文件或目录(代码2)
添加:
private static final String LED = "BCM2";
private Handler mHandler = new Handler();
private Gpio mLedGpio;
PeripheralManager service = PeripheralManager.getInstance();
Log.i(TAG, "Available GPIO: " + service.getGpioList());
try {
mLedGpio = service.openGpio(LED);
mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
Log.i(TAG, "Start blinking LED GPIO pin");
// Post a Runnable that continuously switch the state of the GPIO, blinking the
// corresponding LED
mHandler.post(mBlinkRunnable);
} catch (IOException e) {
Log.e(TAG, "Error on PeripheralIO API", e);
}
代码听起来不错,但问题可能出在GPIO名称上。
查看Raspberry Pi的引脚排列图
您可以看到BCM2不可用(尽管BCM21可用)
您可以看到另一个使用Rainbow HAT on this sample上的引脚的示例。我已经运行并验证了该功能。可以将您的项目与您的项目进行比较,或克隆存储库并尝试使用该代码。