c - 用于 wandboard 的 c GPIO 编程

标签 c shell wand

我如何在c中访问gpio wandboard?

我有一个 ubuntu 14.04 的 wandboard 并希望在我的 c 程序中访问我们的 gpio。 我可以在 shell 脚本中访问,并且可以将脚本放入我的 c 代码中,但我想要一种直接访问 gpio 的模式,而不使用 shell 命令。

这是我的 shell 命令

echo 91 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio91/direction
echo 1 > /sys/class/gpio/gpio91/value
echo 0 > /sys/class/gpio/gpio91/value

最佳答案

只需使用基本的 C 文件 IO。

echo 91 > /sys/class/gpio/export

将是

FILE *fp = fopen("/sys/class/gpio/export", "w");
if (fp) {
    if (fprintf(fp, "91") < 0) {
        perror("fprintf to /sys/class/gpio/export");
    }
    if (fclose(fp) == EOF) {
        // error can very well happen when fclose flushes, must check
        perror("fclose of /sys/class/gpio/export");
    }
} else {
    perror("fopen of /sys/class/gpio/export");
}

将其扩展到其他情况应该很容易。

关于c - 用于 wandboard 的 c GPIO 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26045987/

相关文章:

c - 将 argv 字符串传递给 C 中的函数

c - 用 C 中的值初始化整个数组

linux - 在 bash 脚本中的两个命令之间切换?

bash - 如何欺骗 shebang 允许多个参数?

python - 如何在 python 中使用 wand 对图像进行阈值处理

c - 纳米: how to show object file of a symbol in a shared library?

bash - 我怎样才能在 Bash 中进行 float 比较?

python - 将远程 PDF 页面转换为 OCR 临时图像

Python + Wand.Image - 使用连续的 pagenumber.jpg 名称将输出图像保存到 AWS

c - 当字符串结束后还有空间时,是否用零/空初始化了一个字符数组?