我想使用以下代码编写已导出并设置为输出的GPIO:
private File file;
public void WriteGPIO(View v) {
file = new File("/sys/class/gpio/gpio56/value");
try {
FileOutputStream os = new FileOutputStream (file.getAbsolutePath());
os.write(1);
os.close();
} catch (FileNotFoundException e) {
Log.i("LOG", "write failed : " +e.getMessage());
} catch (IOException e) {
Log.i("LOG", "write failed : " +e.getMessage());
}
}
尝试时出现以下错误:
写入失败:/ sys / class / gpio / gpio56 / value:打开失败:EACCES (许可被拒绝)
有人知道是否可以直接从应用程序以这种方式访问GPIO,或者我是否有义务编写驱动程序来访问它?
谢谢!
答案 0 :(得分:0)
您通常需要先输出引脚并设置引脚的方向,然后才能设置它的输出状态...
echo 56 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio56/direction
echo 1 > /sys/class/gpio/gpio56/value
echo 0 > /sys/class/gpio/gpio56/value